{"thread":{"id":"52001","subject":"How to find the commit that erase a change","startedAt":"2019-10-09T02:36:52Z","lastAt":"2019-10-09T13:21:52Z","messageCount":4,"participants":["wuzhouhui","Junio C Hamano","Derrick Stolee"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"383728","messageId":"5e12e2d8.1ed16.16dae58d6ac.Coremail.wuzhouhui14@mails.ucas.ac.cn","threadId":"52001","inReplyTo":null,"subject":"How to find the commit that erase a change","fromName":"wuzhouhui","fromEmail":"wuzhouhui14@mails.ucas.ac.cn","sentAt":"2019-10-09T02:28:40Z","receivedAt":"2019-10-09T02:36:52Z","isPatch":false,"sender":{"key":"wuzhouhui14@mails.ucas.ac.cn","avatar":null},"body":"Hi,\n\nI have a file which contains complicated change history. When I use\n    git log -p file\nto see all changes made in this file, I found that a change disappeared\nfor no reason.\n\nFor example, I made following change in a commit:\n\n@@ -2,3 +2,8 @@ int main(void)\n {\n        printf(\"hello world\");\n }\n+\n+func(void)\n+{\n+       printf(\"a func\");\n+}\n\nBut when I open this file of latest version, I found the above change is\ndisappeared. So I decide use\n    git log -p file\nto see which commit erase my change. But I doesn't see any commit which\ncontains changes like following:\n\n@@ -2,8 +2,3 @@ int main(void)\n {\n        printf(\"hello world\");\n }\n-\n-func(void)\n-{\n-       printf(\"a func\");\n-}\n\nSo, how to find the commit that erase my change?\n\nThanks. Please use Reply-All when reply this email."},{"id":"383730","messageId":"xmqqmuealiy3.fsf@gitster-ct.c.googlers.com","threadId":"52001","inReplyTo":"5e12e2d8.1ed16.16dae58d6ac.Coremail.wuzhouhui14@mails.ucas.ac.cn","subject":"Re: How to find the commit that erase a change","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-10-09T03:02:44Z","receivedAt":"2019-10-09T03:02:52Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"wuzhouhui <wuzhouhui14@mails.ucas.ac.cn> writes:\n\n> I have a file which contains complicated change history. When I use\n>     git log -p file\n> to see all changes made in this file, I found that a change disappeared\n> for no reason.\n\n\"git log [-p] <pathspec>\" is not about seeing *all* changes made to\nthe path(s) that match the pathspec.  Especially when your history\nhas merges, the command is to give you _one_ simplest explanation as\nto how the contents of the path(s) came to be in the shape you see\nin HEAD.\n\nSo for example, if you have a history like this (time flows from\nleft to right):\n\n    O-----A-----B----M-----N\n           \\        /\n            \\      /\n             X----Y\n\nwhere A or B did *not* touch \"file\", X added a definition of func()\nto \"file\", Y reverted the change X made to \"file\", M made a natural\nmerge between B and Y and N did not touch \"file\", \"git log N file\"\nwould not even show the existence of commits X or Y.  In the larger\npicture, at ancient time O, the file started without func(), and\nnone of the commits A, B, M or N felt the need to add it and as the\nresult, N does not need the unwanted func().  So \"file's contents\nare the same since O throughout the history reaching N\" is given as\n_one_ simplest explanation.\n\nThe \"--full-history\" option may help, though.\n"},{"id":"383731","messageId":"6cfb13f7.1fa14.16daea502c2.Coremail.wuzhouhui14@mails.ucas.ac.cn","threadId":"52001","inReplyTo":"xmqqmuealiy3.fsf@gitster-ct.c.googlers.com","subject":"Re: Re: How to find the commit that erase a change","fromName":"wuzhouhui","fromEmail":"wuzhouhui14@mails.ucas.ac.cn","sentAt":"2019-10-09T03:51:52Z","receivedAt":"2019-10-09T03:52:12Z","isPatch":false,"sender":{"key":"wuzhouhui14@mails.ucas.ac.cn","avatar":null},"body":"> -----Original Messages-----\n> From: \"Junio C Hamano\" <gitster@pobox.com>\n> Sent Time: 2019-10-09 11:02:44 (Wednesday)\n> To: wuzhouhui <wuzhouhui14@mails.ucas.ac.cn>\n> Cc: git@vger.kernel.org, cuifang@sugon.com\n> Subject: Re: How to find the commit that erase a change\n> \n> wuzhouhui <wuzhouhui14@mails.ucas.ac.cn> writes:\n> \n> > I have a file which contains complicated change history. When I use\n> >     git log -p file\n> > to see all changes made in this file, I found that a change disappeared\n> > for no reason.\n> \n> \"git log [-p] <pathspec>\" is not about seeing *all* changes made to\n> the path(s) that match the pathspec.  Especially when your history\n> has merges, the command is to give you _one_ simplest explanation as\n> to how the contents of the path(s) came to be in the shape you see\n> in HEAD.\n> \n> So for example, if you have a history like this (time flows from\n> left to right):\n> \n>     O-----A-----B----M-----N\n>            \\        /\n>             \\      /\n>              X----Y\n> \n> where A or B did *not* touch \"file\", X added a definition of func()\n> to \"file\", Y reverted the change X made to \"file\", M made a natural\n> merge between B and Y and N did not touch \"file\", \"git log N file\"\n> would not even show the existence of commits X or Y.  In the larger\n> picture, at ancient time O, the file started without func(), and\n> none of the commits A, B, M or N felt the need to add it and as the\n> result, N does not need the unwanted func().  So \"file's contents\n> are the same since O throughout the history reaching N\" is given as\n> _one_ simplest explanation.\n> \n> The \"--full-history\" option may help, though.\n\n\"--full-history\" doesn't resolve my problem, but\n    git log -p -c file\ndoes. I found that my change was erased in a merge commit.\n\nThanks."},{"id":"383748","messageId":"67016186-a9ff-be2b-883d-bc93af48aad8@gmail.com","threadId":"52001","inReplyTo":"6cfb13f7.1fa14.16daea502c2.Coremail.wuzhouhui14@mails.ucas.ac.cn","subject":"Re: How to find the commit that erase a change","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2019-10-09T13:21:48Z","receivedAt":"2019-10-09T13:21:52Z","isPatch":false,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 10/8/2019 11:51 PM, wuzhouhui wrote:\n>> -----Original Messages-----\n>> From: \"Junio C Hamano\" <gitster@pobox.com>\n>> Sent Time: 2019-10-09 11:02:44 (Wednesday)\n>> To: wuzhouhui <wuzhouhui14@mails.ucas.ac.cn>\n>> Cc: git@vger.kernel.org, cuifang@sugon.com\n>> Subject: Re: How to find the commit that erase a change\n>>\n>> wuzhouhui <wuzhouhui14@mails.ucas.ac.cn> writes:\n>>\n>>> I have a file which contains complicated change history. When I use\n>>>     git log -p file\n>>> to see all changes made in this file, I found that a change disappeared\n>>> for no reason.\n>>\n>> \"git log [-p] <pathspec>\" is not about seeing *all* changes made to\n>> the path(s) that match the pathspec.  Especially when your history\n>> has merges, the command is to give you _one_ simplest explanation as\n>> to how the contents of the path(s) came to be in the shape you see\n>> in HEAD.\n>>\n>> So for example, if you have a history like this (time flows from\n>> left to right):\n>>\n>>     O-----A-----B----M-----N\n>>            \\        /\n>>             \\      /\n>>              X----Y\n>>\n>> where A or B did *not* touch \"file\", X added a definition of func()\n>> to \"file\", Y reverted the change X made to \"file\", M made a natural\n>> merge between B and Y and N did not touch \"file\", \"git log N file\"\n>> would not even show the existence of commits X or Y.  In the larger\n>> picture, at ancient time O, the file started without func(), and\n>> none of the commits A, B, M or N felt the need to add it and as the\n>> result, N does not need the unwanted func().  So \"file's contents\n>> are the same since O throughout the history reaching N\" is given as\n>> _one_ simplest explanation.\n>>\n>> The \"--full-history\" option may help, though.\n> \n> \"--full-history\" doesn't resolve my problem, but\n>     git log -p -c file\n> does. I found that my change was erased in a merge commit.\n\nIn these cases of erased merge commits, I find that\n\n\tgit log --simplify-merges -- file\n\nworks best for finding the merge responsible. Just the\n--full-history option may include many extra merges (if you\nwork in a repo with many collaborators).\n\nThanks,\n-Stolee\n"}]}