{"thread":{"id":"10030","subject":"[PATCH] git-commit --amend: respect grafted parents.","startedAt":"2007-09-26T12:11:36Z","lastAt":"2007-09-27T08:39:12Z","messageCount":8,"participants":["Johannes Sixt","Johannes Schindelin","Junio C Hamano","David Kastrup"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"54095","messageId":"11908086961933-git-send-email-johannes.sixt@telecom.at","threadId":"10030","inReplyTo":null,"subject":"[PATCH] git-commit --amend: respect grafted parents.","fromName":"Johannes Sixt","fromEmail":"johannes.sixt@telecom.at","sentAt":"2007-09-26T12:11:36Z","receivedAt":"2007-09-26T12:11:36Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"This allows a poor-mans-filter-branch of the top-most commit.\n\nSpecifically, I had this history:\n\n   --o--o--A'    <-- amended version of A\n         \\\n          A\n           \\\n    --o--B--M\n\nI now wanted to \"amend\" M to pull in A' instead of A as its second parent.\nFor various reasons I didn't want to redo the merge M again, in particular,\nit already contained the changes that were amended into A'. So I figured\nI would just install a graft that lists B and A' as parents of M and then\ndo a simple git commit --amend. Alas, git commit looks at the real parents\ninstead of the grafted ones, so the amended M' would still have A as its\nsecond parent. Here is the fix that picks the grafted parents instead.\n\nSigned-off-by: Johannes Sixt <johannes.sixt@telecom.at>\n---\n  I know that git-commit is becoming a builtin. At the least, here is\n  a test that makes sure that the behavior is remains.\n\n  -- Hannes\n\n git-commit.sh     |    4 ++--\n t/t7501-commit.sh |    9 +++++++++\n 2 files changed, 11 insertions(+), 2 deletions(-)\n mode change 100644 => 100755 t/t7501-commit.sh\n\ndiff --git a/git-commit.sh b/git-commit.sh\nindex 7a7a2cb..33e7503 100755\n--- a/git-commit.sh\n+++ b/git-commit.sh\n@@ -529,8 +529,8 @@ then\n \t\tPARENTS=\"-p HEAD \"`sed -e 's/^/-p /' \"$GIT_DIR/MERGE_HEAD\"`\n \telif test -n \"$amend\"; then\n \t\trloga='commit (amend)'\n-\t\tPARENTS=$(git cat-file commit HEAD |\n-\t\t\tsed -n -e '/^$/q' -e 's/^parent /-p /p')\n+\t\tPARENTS=$(git rev-list --parents -1 HEAD |\n+\t\t\tsed -e 's/^[^ ]*//' -e 's/ / -p /g')\n \tfi\n \tcurrent=\"$(git rev-parse --verify HEAD)\"\n else\ndiff --git a/t/t7501-commit.sh b/t/t7501-commit.sh\nold mode 100644\nnew mode 100755\nindex b151b51..09c0d98\n--- a/t/t7501-commit.sh\n+++ b/t/t7501-commit.sh\n@@ -163,4 +163,13 @@ test_expect_success 'partial commit that involves removal (3)' '\n \n '\n \n+test_expect_success '--amend respects grafts' '\n+\n+\tgrandparent=$(git rev-parse HEAD~2) &&\n+\techo $(git rev-parse HEAD) $grandparent > .git/info/grafts &&\n+\tgit commit --amend -C HEAD &&\n+\ttest \"parent $grandparent\" = \"$(git cat-file commit HEAD | grep \"^parent\")\"\n+\n+'\n+\n test_done\n-- \n1.5.3.3.gcc9e\n"},{"id":"54096","messageId":"Pine.LNX.4.64.0709261322150.28395@racer.site","threadId":"10030","inReplyTo":"11908086961933-git-send-email-johannes.sixt@telecom.at","subject":"Re: [PATCH] git-commit --amend: respect grafted parents.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-09-26T12:24:23Z","receivedAt":"2007-09-26T12:24:23Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 26 Sep 2007, Johannes Sixt wrote:\n\n> This allows a poor-mans-filter-branch of the top-most commit.\n> \n> Specifically, I had this history:\n> \n>    --o--o--A'    <-- amended version of A\n>          \\\n>           A\n>            \\\n>     --o--B--M\n> \n> I now wanted to \"amend\" M to pull in A' instead of A as its second \n> parent. For various reasons I didn't want to redo the merge M again, in \n> particular, it already contained the changes that were amended into A'. \n> So I figured I would just install a graft that lists B and A' as parents \n> of M and then do a simple git commit --amend. Alas, git commit looks at \n> the real parents instead of the grafted ones, so the amended M' would \n> still have A as its second parent. Here is the fix that picks the \n> grafted parents instead.\n\nI do not think that this is a \"fix\".\n\nI'd really suggest that you fix it up (before the amend!) by installing \nthe graft, and running git-filter-branch -1 <branch>.  (Note: I did not \ntest this, but it _should_ work.  If it does not, please let me know.)\n\nCiao,\nDscho\n"},{"id":"54098","messageId":"46FA5604.101@viscovery.net","threadId":"10030","inReplyTo":"Pine.LNX.4.64.0709261322150.28395@racer.site","subject":"Re: [PATCH] git-commit --amend: respect grafted parents.","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2007-09-26T12:52:20Z","receivedAt":"2007-09-26T12:52:20Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Johannes Schindelin schrieb:\n> Hi,\n> \n> On Wed, 26 Sep 2007, Johannes Sixt wrote:\n> \n>> This allows a poor-mans-filter-branch of the top-most commit.\n>>\n>> Specifically, I had this history:\n>>\n>>    --o--o--A'    <-- amended version of A\n>>          \\\n>>           A\n>>            \\\n>>     --o--B--M\n>>\n>> I now wanted to \"amend\" M to pull in A' instead of A as its second \n>> parent. For various reasons I didn't want to redo the merge M again, in \n>> particular, it already contained the changes that were amended into A'. \n>> So I figured I would just install a graft that lists B and A' as parents \n>> of M and then do a simple git commit --amend. Alas, git commit looks at \n>> the real parents instead of the grafted ones, so the amended M' would \n>> still have A as its second parent. Here is the fix that picks the \n>> grafted parents instead.\n> \n> I do not think that this is a \"fix\".\n> \n> I'd really suggest that you fix it up (before the amend!) by installing \n> the graft, and running git-filter-branch -1 <branch>.  (Note: I did not \n> test this, but it _should_ work.  If it does not, please let me know.)\n\nThe problem with filter-branch is that it leaves a committer date in M that \nis before A', and for this reason is not the right tool for this task. So I \ndo think that this fix is necessary.\n\n-- Hannes\n"},{"id":"54100","messageId":"Pine.LNX.4.64.0709261501190.28395@racer.site","threadId":"10030","inReplyTo":"46FA5604.101@viscovery.net","subject":"Re: [PATCH] git-commit --amend: respect grafted parents.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-09-26T14:03:40Z","receivedAt":"2007-09-26T14:03:40Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 26 Sep 2007, Johannes Sixt wrote:\n\n> Johannes Schindelin schrieb:\n> \n> > On Wed, 26 Sep 2007, Johannes Sixt wrote:\n> > \n> > > This allows a poor-mans-filter-branch of the top-most commit.\n> > > \n> > > Specifically, I had this history:\n> > > \n> > >    --o--o--A'    <-- amended version of A\n> > >          \\\n> > >           A\n> > >            \\\n> > >     --o--B--M\n> > > \n> > > I now wanted to \"amend\" M to pull in A' instead of A as its second \n> > > parent. For various reasons I didn't want to redo the merge M again, \n> > > in particular, it already contained the changes that were amended \n> > > into A'. So I figured I would just install a graft that lists B and \n> > > A' as parents of M and then do a simple git commit --amend. Alas, \n> > > git commit looks at the real parents instead of the grafted ones, so \n> > > the amended M' would still have A as its second parent. Here is the \n> > > fix that picks the grafted parents instead.\n> > \n> > I do not think that this is a \"fix\".\n> > \n> > I'd really suggest that you fix it up (before the amend!) by \n> > installing the graft, and running git-filter-branch -1 <branch>.  \n> > (Note: I did not test this, but it _should_ work.  If it does not, \n> > please let me know.)\n> \n> The problem with filter-branch is that it leaves a committer date in M \n> that is before A', and for this reason is not the right tool for this \n> task. So I do think that this fix is necessary.\n\nBut that's easily fixed with \"--env-filter 'export \nGIT_COMMITTER_DATE=$(date +%s)'\" or something similar.\n\nThe reason why I insist on not putting this into --amend is that I think \nthis is not really an amend, but actively a rewrite of the merge commit.  \n\nCiao,\nDscho\n"},{"id":"54103","messageId":"46FA6CD7.1020709@viscovery.net","threadId":"10030","inReplyTo":"Pine.LNX.4.64.0709261501190.28395@racer.site","subject":"Re: [PATCH] git-commit --amend: respect grafted parents.","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2007-09-26T14:29:43Z","receivedAt":"2007-09-26T14:29:43Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Johannes Schindelin schrieb:\n> The reason why I insist on not putting this into --amend is that I think \n> this is not really an amend, but actively a rewrite of the merge commit.  \n\nYou have a point here. I'm convinced. Scrap the patch.\n\n-- Hannes\n"},{"id":"54109","messageId":"7vd4w51csv.fsf@gitster.siamese.dyndns.org","threadId":"10030","inReplyTo":"46FA6CD7.1020709@viscovery.net","subject":"Re: [PATCH] git-commit --amend: respect grafted parents.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-09-26T18:50:24Z","receivedAt":"2007-09-26T18:50:24Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Sixt <j.sixt@viscovery.net> writes:\n\n> Johannes Schindelin schrieb:\n>> The reason why I insist on not putting this into --amend is that I\n>> think this is not really an amend, but actively a rewrite of the\n>> merge commit.\n>\n> You have a point here. I'm convinced. Scrap the patch.\n\nI am slow today.  Since when --amend is not about \"a rewrite of\ncommit\"?\n"},{"id":"54111","messageId":"Pine.LNX.4.64.0709262039250.28395@racer.site","threadId":"10030","inReplyTo":"7vd4w51csv.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] git-commit --amend: respect grafted parents.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-09-26T19:47:49Z","receivedAt":"2007-09-26T19:47:49Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 26 Sep 2007, Junio C Hamano wrote:\n\n> Johannes Sixt <j.sixt@viscovery.net> writes:\n> \n> > Johannes Schindelin schrieb:\n> >> The reason why I insist on not putting this into --amend is that I \n> >> think this is not really an amend, but actively a rewrite of the \n> >> merge commit.\n> >\n> > You have a point here. I'm convinced. Scrap the patch.\n> \n> I am slow today.  Since when --amend is not about \"a rewrite of commit\"?\n\nTechnically, you are right, of course.  Commit objects are immutable.  But \nfrom a _porcelain_ view I maintain that \"amending\" is about changes _to_ a \ncommit.  It is not about redefining the (a) parent.\n\nCiao,\nDscho\n"},{"id":"54146","messageId":"86hclgijtb.fsf@lola.quinscape.zz","threadId":"10030","inReplyTo":"Pine.LNX.4.64.0709262039250.28395@racer.site","subject":"Re: [PATCH] git-commit --amend: respect grafted parents.","fromName":"David Kastrup","fromEmail":"dak@gnu.org","sentAt":"2007-09-27T08:39:12Z","receivedAt":"2007-09-27T08:39:12Z","isPatch":true,"sender":{"key":"dak@gnu.org","avatar":"https://avatars.githubusercontent.com/u/52141349?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> Hi,\n>\n> On Wed, 26 Sep 2007, Junio C Hamano wrote:\n>\n>> Johannes Sixt <j.sixt@viscovery.net> writes:\n>> \n>> > Johannes Schindelin schrieb:\n>> >> The reason why I insist on not putting this into --amend is that I \n>> >> think this is not really an amend, but actively a rewrite of the \n>> >> merge commit.\n>> >\n>> > You have a point here. I'm convinced. Scrap the patch.\n>> \n>> I am slow today.  Since when --amend is not about \"a rewrite of commit\"?\n>\n> Technically, you are right, of course.  Commit objects are immutable.  But \n> from a _porcelain_ view I maintain that \"amending\" is about changes _to_ a \n> commit.  It is not about redefining the (a) parent.\n\nWell, if you already branched off the commit, the changes \"to the\ncommit\" will not register on the branch.  So my view is that amending\nis about changes to HEAD, not to the HEAD commit.  And since branching\nis certainly a porcelain operation and is clearly not affected by\namending commits, I think that the \"rewrite of a commit\" wording\nstrikes a good balance between \"the original commit remains\" and \"it\nis functionally replaced in the HEAD\".\n\n-- \nDavid Kastrup\n"}]}