git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / Atom feed
* How to find the commit that erase a change
@ 2019-10-09  2:28 wuzhouhui
  2019-10-09  3:02 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: wuzhouhui @ 2019-10-09  2:28 UTC (permalink / raw)
  To: git; +Cc: cuifang

Hi,

I have a file which contains complicated change history. When I use
    git log -p file
to see all changes made in this file, I found that a change disappeared
for no reason.

For example, I made following change in a commit:

@@ -2,3 +2,8 @@ int main(void)
 {
        printf("hello world");
 }
+
+func(void)
+{
+       printf("a func");
+}

But when I open this file of latest version, I found the above change is
disappeared. So I decide use
    git log -p file
to see which commit erase my change. But I doesn't see any commit which
contains changes like following:

@@ -2,8 +2,3 @@ int main(void)
 {
        printf("hello world");
 }
-
-func(void)
-{
-       printf("a func");
-}

So, how to find the commit that erase my change?

Thanks. Please use Reply-All when reply this email.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to find the commit that erase a change
  2019-10-09  2:28 How to find the commit that erase a change wuzhouhui
@ 2019-10-09  3:02 ` Junio C Hamano
  2019-10-09  3:51   ` wuzhouhui
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2019-10-09  3:02 UTC (permalink / raw)
  To: wuzhouhui; +Cc: git, cuifang

wuzhouhui <wuzhouhui14@mails.ucas.ac.cn> writes:

> I have a file which contains complicated change history. When I use
>     git log -p file
> to see all changes made in this file, I found that a change disappeared
> for no reason.

"git log [-p] <pathspec>" is not about seeing *all* changes made to
the path(s) that match the pathspec.  Especially when your history
has merges, the command is to give you _one_ simplest explanation as
to how the contents of the path(s) came to be in the shape you see
in HEAD.

So for example, if you have a history like this (time flows from
left to right):

    O-----A-----B----M-----N
           \        /
            \      /
             X----Y

where A or B did *not* touch "file", X added a definition of func()
to "file", Y reverted the change X made to "file", M made a natural
merge between B and Y and N did not touch "file", "git log N file"
would not even show the existence of commits X or Y.  In the larger
picture, at ancient time O, the file started without func(), and
none of the commits A, B, M or N felt the need to add it and as the
result, N does not need the unwanted func().  So "file's contents
are the same since O throughout the history reaching N" is given as
_one_ simplest explanation.

The "--full-history" option may help, though.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Re: How to find the commit that erase a change
  2019-10-09  3:02 ` Junio C Hamano
@ 2019-10-09  3:51   ` wuzhouhui
  2019-10-09 13:21     ` Derrick Stolee
  0 siblings, 1 reply; 4+ messages in thread
From: wuzhouhui @ 2019-10-09  3:51 UTC (permalink / raw)
  To: junio c hamano; +Cc: git, cuifang

> -----Original Messages-----
> From: "Junio C Hamano" <gitster@pobox.com>
> Sent Time: 2019-10-09 11:02:44 (Wednesday)
> To: wuzhouhui <wuzhouhui14@mails.ucas.ac.cn>
> Cc: git@vger.kernel.org, cuifang@sugon.com
> Subject: Re: How to find the commit that erase a change
> 
> wuzhouhui <wuzhouhui14@mails.ucas.ac.cn> writes:
> 
> > I have a file which contains complicated change history. When I use
> >     git log -p file
> > to see all changes made in this file, I found that a change disappeared
> > for no reason.
> 
> "git log [-p] <pathspec>" is not about seeing *all* changes made to
> the path(s) that match the pathspec.  Especially when your history
> has merges, the command is to give you _one_ simplest explanation as
> to how the contents of the path(s) came to be in the shape you see
> in HEAD.
> 
> So for example, if you have a history like this (time flows from
> left to right):
> 
>     O-----A-----B----M-----N
>            \        /
>             \      /
>              X----Y
> 
> where A or B did *not* touch "file", X added a definition of func()
> to "file", Y reverted the change X made to "file", M made a natural
> merge between B and Y and N did not touch "file", "git log N file"
> would not even show the existence of commits X or Y.  In the larger
> picture, at ancient time O, the file started without func(), and
> none of the commits A, B, M or N felt the need to add it and as the
> result, N does not need the unwanted func().  So "file's contents
> are the same since O throughout the history reaching N" is given as
> _one_ simplest explanation.
> 
> The "--full-history" option may help, though.

"--full-history" doesn't resolve my problem, but
    git log -p -c file
does. I found that my change was erased in a merge commit.

Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to find the commit that erase a change
  2019-10-09  3:51   ` wuzhouhui
@ 2019-10-09 13:21     ` Derrick Stolee
  0 siblings, 0 replies; 4+ messages in thread
From: Derrick Stolee @ 2019-10-09 13:21 UTC (permalink / raw)
  To: wuzhouhui, junio c hamano; +Cc: git, cuifang

On 10/8/2019 11:51 PM, wuzhouhui wrote:
>> -----Original Messages-----
>> From: "Junio C Hamano" <gitster@pobox.com>
>> Sent Time: 2019-10-09 11:02:44 (Wednesday)
>> To: wuzhouhui <wuzhouhui14@mails.ucas.ac.cn>
>> Cc: git@vger.kernel.org, cuifang@sugon.com
>> Subject: Re: How to find the commit that erase a change
>>
>> wuzhouhui <wuzhouhui14@mails.ucas.ac.cn> writes:
>>
>>> I have a file which contains complicated change history. When I use
>>>     git log -p file
>>> to see all changes made in this file, I found that a change disappeared
>>> for no reason.
>>
>> "git log [-p] <pathspec>" is not about seeing *all* changes made to
>> the path(s) that match the pathspec.  Especially when your history
>> has merges, the command is to give you _one_ simplest explanation as
>> to how the contents of the path(s) came to be in the shape you see
>> in HEAD.
>>
>> So for example, if you have a history like this (time flows from
>> left to right):
>>
>>     O-----A-----B----M-----N
>>            \        /
>>             \      /
>>              X----Y
>>
>> where A or B did *not* touch "file", X added a definition of func()
>> to "file", Y reverted the change X made to "file", M made a natural
>> merge between B and Y and N did not touch "file", "git log N file"
>> would not even show the existence of commits X or Y.  In the larger
>> picture, at ancient time O, the file started without func(), and
>> none of the commits A, B, M or N felt the need to add it and as the
>> result, N does not need the unwanted func().  So "file's contents
>> are the same since O throughout the history reaching N" is given as
>> _one_ simplest explanation.
>>
>> The "--full-history" option may help, though.
> 
> "--full-history" doesn't resolve my problem, but
>     git log -p -c file
> does. I found that my change was erased in a merge commit.

In these cases of erased merge commits, I find that

	git log --simplify-merges -- file

works best for finding the merge responsible. Just the
--full-history option may include many extra merges (if you
work in a repo with many collaborators).

Thanks,
-Stolee

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-09  2:28 How to find the commit that erase a change wuzhouhui
2019-10-09  3:02 ` Junio C Hamano
2019-10-09  3:51   ` wuzhouhui
2019-10-09 13:21     ` Derrick Stolee

git@vger.kernel.org list mirror (unofficial, one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox