{"thread":{"id":"45718","subject":"How to keep log history when renaming and changing simultaneously","startedAt":"2017-04-17T11:45:49Z","lastAt":"2017-04-18T03:21:01Z","messageCount":6,"participants":["Urs Thuermann","Duy Nguyen","Igor Djordjevic","Jacob Keller","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"317003","messageId":"ygfpogbb711.fsf@tehran.isnogud.escape.de","threadId":"45718","inReplyTo":null,"subject":"How to keep log history when renaming and changing simultaneously","fromName":"Urs Thuermann","fromEmail":"urs@isnogud.escape.de","sentAt":"2017-04-17T11:36:10Z","receivedAt":"2017-04-17T11:45:49Z","isPatch":false,"sender":{"key":"urs@isnogud.escape.de","avatar":"https://avatars.githubusercontent.com/u/11499339?v=4"},"body":"Sometimes I need to rename and change a file in one commit.  One\nexample would be a file foo.h that begins with\n\n    #ifndef FOO_H\n    #define FOO_H\n\nwhich should be renamed bar.h and have the FOO_H changed to BAR_H.\nIn subversion I would\n\n    svn mv foo.h bar.h; vi bar.h; svn ci\n\nand then a\n\n    svn log bar.h\n\nalso shows the history of that file when it was named foo.h.\n\nThis does not work in git.  After committing,\n\n    git mv foo.h bar.h; vi bar.h; git commit -a\n\nthe command\n\n    git log --follow bar.h\n\nshows only the history of the file when it was named bar.h, but not\nits life as foo.h.\n\nThe only workaround I found was to do the rename and the change in two\nseparate commits, so that git sees the same name and the same SHA hash\nwhich allows it to follow the files' history.  This can be a problem\nwhen the intermediate version with either only the change or only the\nrename doesn't compile correctly.\n\nIs there a better way to do this in git?\n\nA similar problem is splitting a file into two files.  With subversion\nI'd do\n\n    printf \"void foo() {}\\nint main() { foo(); }\\n\" > prog.c\n    svn add prog.c; svn ci -m \"Add prog.c\"\n\nThen I would split\n\n    svn cp prog.c foo.c; svn cp prog.c main.c; svn rm prog.c\n    printf \"2d\\nwq\\n\" | ed foo.c; printf \"1d\\nwq\\n\" | ed main.c\n    svn ci -m \"Split prog.c\"; svn up\n\nand I get\n\n    $ svn log -v\n    ------------------------------------------------------------------------\n    r2 | urs | 2017-04-17 10:03:06 +0200 (Mon, 17 Apr 2017) | 1 line\n    Changed paths:\n       A /foo.c (from /prog.c:1)\n       A /main.c (from /prog.c:1)\n       D /prog.c\n    \n    Split prog.c\n    ------------------------------------------------------------------------\n    r1 | urs | 2017-04-17 10:02:51 +0200 (Mon, 17 Apr 2017) | 1 line\n    Changed paths:\n       A /prog.c\n    \n    Add prog.c\n    ------------------------------------------------------------------------\n\nAnd I can also see this when I run svn log on one of both files.\t\nHow could I do this in git?\n\nurs\n"},{"id":"317005","messageId":"CACsJy8B5r+Xoo8s9xbwaUrQhEODzN4Uk5z9RjbKXMwM-W5m=HQ@mail.gmail.com","threadId":"45718","inReplyTo":"ygfpogbb711.fsf@tehran.isnogud.escape.de","subject":"Re: How to keep log history when renaming and changing simultaneously","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2017-04-17T12:17:18Z","receivedAt":"2017-04-17T12:17:54Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Mon, Apr 17, 2017 at 6:36 PM, Urs Thuermann <urs@isnogud.escape.de> wrote:\n> Sometimes I need to rename and change a file in one commit.  One\n> example would be a file foo.h that begins with\n>\n>     #ifndef FOO_H\n>     #define FOO_H\n>\n> which should be renamed bar.h and have the FOO_H changed to BAR_H.\n> In subversion I would\n>\n>     svn mv foo.h bar.h; vi bar.h; svn ci\n>\n> and then a\n>\n>     svn log bar.h\n>\n> also shows the history of that file when it was named foo.h.\n>\n> This does not work in git.\n> ...\n> Is there a better way to do this in git?\n\nWe could if we allowed rename annotation, similar to that \"svn mv\"\ncommand. I worked on that a while back [1] then I stopped because of a\ndesign conflict. But I'm almost convinced Jeff and Junio were right\n(and I wrong) now so I will likely revive that series before 2019\nhits.\n\n[1] http://public-inbox.org/git/1453287968-26000-1-git-send-email-pclouds@gmail.com/\n-- \nDuy\n"},{"id":"317021","messageId":"f456df1f-cda2-4681-8f01-b693655e79a7@gmail.com","threadId":"45718","inReplyTo":"ygfpogbb711.fsf@tehran.isnogud.escape.de","subject":"Re: How to keep log history when renaming and changing simultaneously","fromName":"Igor Djordjevic","fromEmail":"igor.d.djordjevic@gmail.com","sentAt":"2017-04-17T20:34:32Z","receivedAt":"2017-04-17T20:34:43Z","isPatch":false,"sender":{"key":"igor.d.djordjevic@gmail.com","avatar":null},"body":"Hi Urs,\n\nOn 17/04/2017 13:36, Urs Thuermann wrote:\n> Sometimes I need to rename and change a file in one commit.  One\n> example would be a file foo.h that begins with\n> \n>     #ifndef FOO_H\n>     #define FOO_H\n> \n> which should be renamed bar.h and have the FOO_H changed to BAR_H.\n> In subversion I would\n> \n>     svn mv foo.h bar.h; vi bar.h; svn ci\n> \n> and then a\n> \n>     svn log bar.h\n> \n> also shows the history of that file when it was named foo.h.\n> \n> This does not work in git.  After committing,\n> \n>     git mv foo.h bar.h; vi bar.h; git commit -a\n> \n> the command\n> \n>     git log --follow bar.h\n> \n> shows only the history of the file when it was named bar.h, but not\n> its life as foo.h.\n> \n> The only workaround I found was to do the rename and the change in two\n> separate commits, so that git sees the same name and the same SHA hash\n> which allows it to follow the files' history.  This can be a problem\n> when the intermediate version with either only the change or only the\n> rename doesn't compile correctly.\n> \n> Is there a better way to do this in git?\n> \n> A similar problem is splitting a file into two files.  With subversion\n> I'd do\n> \n>     printf \"void foo() {}\\nint main() { foo(); }\\n\" > prog.c\n>     svn add prog.c; svn ci -m \"Add prog.c\"\n> \n> Then I would split\n> \n>     svn cp prog.c foo.c; svn cp prog.c main.c; svn rm prog.c\n>     printf \"2d\\nwq\\n\" | ed foo.c; printf \"1d\\nwq\\n\" | ed main.c\n>     svn ci -m \"Split prog.c\"; svn up\n> \n> and I get\n> \n>     $ svn log -v\n>     ------------------------------------------------------------------------\n>     r2 | urs | 2017-04-17 10:03:06 +0200 (Mon, 17 Apr 2017) | 1 line\n>     Changed paths:\n>        A /foo.c (from /prog.c:1)\n>        A /main.c (from /prog.c:1)\n>        D /prog.c\n>     \n>     Split prog.c\n>     ------------------------------------------------------------------------\n>     r1 | urs | 2017-04-17 10:02:51 +0200 (Mon, 17 Apr 2017) | 1 line\n>     Changed paths:\n>        A /prog.c\n>     \n>     Add prog.c\n>     ------------------------------------------------------------------------\n> \n> And I can also see this when I run svn log on one of both files.\t\n> How could I do this in git?\n\nFor both cases (renaming and splitting), would using `--find-copies` \nwork for you? Perhaps with some low threshold value to start with, if \nthe default one yields no results.\n\nIf interested, adding `--name-status` to the mix will show similarity \npercentage between old and new file(s).\n\n\nFor example, renaming (with edit):\n\n    git log --follow --find-copies=10% --name-status -- bar.h\n\n... yields something like this (sha1/author/date/message omitted \nfor brevity):\n\n    commit 2\n    ...\n    R034    foo.h   bar.h\n\n    commit 1\n    ...\n    A       foo.h\n\n\nAnother example, splitting (with minor edits):\n\n    git log --find-copies --name-status\n\n... outputs something like this:\n\n    commit 2\n    ...\n    C090    prog.c  foo.c\n    R090    prog.c  main.c\n\n    commit 1\n    ...\n    A       prog.c\n\n\nRegards,\nBuga\n"},{"id":"317035","messageId":"ygfefwqzph7.fsf@tehran.isnogud.escape.de","threadId":"45718","inReplyTo":"f456df1f-cda2-4681-8f01-b693655e79a7@gmail.com","subject":"Re: How to keep log history when renaming and changing simultaneously","fromName":"Urs Thuermann","fromEmail":"urs@isnogud.escape.de","sentAt":"2017-04-17T21:36:04Z","receivedAt":"2017-04-17T21:40:12Z","isPatch":false,"sender":{"key":"urs@isnogud.escape.de","avatar":"https://avatars.githubusercontent.com/u/11499339?v=4"},"body":"Igor Djordjevic <igor.d.djordjevic@gmail.com> writes:\n\n> For both cases (renaming and splitting), would using `--find-copies` \n> work for you? Perhaps with some low threshold value to start with, if \n> the default one yields no results.\n> \n> If interested, adding `--name-status` to the mix will show similarity \n> percentage between old and new file(s).\n\nI didn't know --find-copies and --name-status and I've now looked them\nup in the doc.  Looks interesting but instead of looking for\nsimilarity it would be better IMHO if there was a command \"git cp\" and\nthat \"git mv\" and \"git cp\" were recorded in the history somehow.\n\nI'm still using CVS (and SVN in some few cases) but considering\nchanging to git.  There are some things, however, that I can do more\neasily in CVS (like editing CVS ,v files instead of git commit\n--amend) and I need to learn more git before I want to change (and\nmigrate existing repos).\n\nurs\n"},{"id":"317057","messageId":"CA+P7+xpWMdoQj5FxkN=7QKc3UvW77HsTDs5RRZiCg4WVnB4wqA@mail.gmail.com","threadId":"45718","inReplyTo":"ygfefwqzph7.fsf@tehran.isnogud.escape.de","subject":"Re: How to keep log history when renaming and changing simultaneously","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2017-04-18T01:15:42Z","receivedAt":"2017-04-18T01:16:11Z","isPatch":false,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Mon, Apr 17, 2017 at 2:36 PM, Urs Thuermann <urs@isnogud.escape.de> wrote:\n> Igor Djordjevic <igor.d.djordjevic@gmail.com> writes:\n>\n>> For both cases (renaming and splitting), would using `--find-copies`\n>> work for you? Perhaps with some low threshold value to start with, if\n>> the default one yields no results.\n>>\n>> If interested, adding `--name-status` to the mix will show similarity\n>> percentage between old and new file(s).\n>\n> I didn't know --find-copies and --name-status and I've now looked them\n> up in the doc.  Looks interesting but instead of looking for\n> similarity it would be better IMHO if there was a command \"git cp\" and\n> that \"git mv\" and \"git cp\" were recorded in the history somehow.\n>\n> I'm still using CVS (and SVN in some few cases) but considering\n> changing to git.  There are some things, however, that I can do more\n> easily in CVS (like editing CVS ,v files instead of git commit\n> --amend) and I need to learn more git before I want to change (and\n> migrate existing repos).\n>\n> urs\n\nUnfortunately I don't have a ready link to the message, but there is a\nvery good post from early on in Git's development where Linus explains\nwhy Git does not store rename and copy information in the history.\n\nEssentially, it's because that information can be regenerated from the\nblobs later, and you can get better information with better algorithms\nand you don't bake the original implementation into the history\nforever.\n\nThanks,\nJake\n"},{"id":"317068","messageId":"xmqqr30qflk9.fsf@gitster.mtv.corp.google.com","threadId":"45718","inReplyTo":"CA+P7+xpWMdoQj5FxkN=7QKc3UvW77HsTDs5RRZiCg4WVnB4wqA@mail.gmail.com","subject":"Re: How to keep log history when renaming and changing simultaneously","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-04-18T03:20:54Z","receivedAt":"2017-04-18T03:21:01Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jacob Keller <jacob.keller@gmail.com> writes:\n\n> Unfortunately I don't have a ready link to the message, but there is a\n> very good post from early on in Git's development where Linus explains\n> why Git does not store rename and copy information in the history.\n\nOne of the most important message in the list archive, gmane:217 aka\n\nhttp://public-inbox.org/git/Pine.LNX.4.58.0504150753440.7211@ppc970.osdl.org/\n\n"}]}