{"thread":{"id":"57092","subject":"bug?: ORIG_HEAD incorrect after reset during git-rebase -i","startedAt":"2021-12-16T14:31:01Z","lastAt":"2023-01-07T19:50:53Z","messageCount":7,"participants":["Erik Cervin Edin","Phillip Wood","Philippe Blain"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"444229","messageId":"CA+JQ7M-ynq1cLN-3ZodXae=x-H5k7Ab6uPBwUFhG+kgtOvCgtA@mail.gmail.com","threadId":"57092","inReplyTo":null,"subject":"bug?: ORIG_HEAD incorrect after reset during git-rebase -i","fromName":"Erik Cervin Edin","fromEmail":"erik@cervined.in","sentAt":"2021-12-16T14:30:24Z","receivedAt":"2021-12-16T14:31:01Z","isPatch":false,"sender":{"key":"erik@cervined.in","avatar":null},"body":"Steps to reproduce:\n1. git-rebase -i\n2. edit XYZ\n3. git-reset HEAD~\n4. git-commit -C ORIG_HEAD -a\n5. git-rebase --continue\n6. git-show ORIG_HEAD\n\nExpected behavior:\nORIG_HEAD should point at the previous HEAD of the rebased branch\n\nActual behavior:\nORIG_HEAD points to XYZ\n\nMy understanding from reading https://stackoverflow.com/a/64949884 is\nthat this is incorrect behavior.\n\nPerhaps this is as intended but I would at least personally prefer\nthat ORIG_HEAD would point to the previous HEAD of the rebased branch.\n\nSeen in:\ngit version 2.31.1.windows.1\n\nPossibly related to\ne100bea481 - rebase -i: stop overwriting ORIG_HEAD buffer\n"},{"id":"444240","messageId":"e6adaad6-f6ee-57d3-dc8f-d14a760c57c2@talktalk.net","threadId":"57092","inReplyTo":"CA+JQ7M-ynq1cLN-3ZodXae=x-H5k7Ab6uPBwUFhG+kgtOvCgtA@mail.gmail.com","subject":"Re: bug?: ORIG_HEAD incorrect after reset during git-rebase -i","fromName":"Phillip Wood","fromEmail":"phillip.wood@talktalk.net","sentAt":"2021-12-16T16:27:54Z","receivedAt":"2021-12-16T16:36:05Z","isPatch":false,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Erik\n\nOn 16/12/2021 14:30, Erik Cervin Edin wrote:\n> Steps to reproduce:\n> 1. git-rebase -i\n> 2. edit XYZ\n> 3. git-reset HEAD~\n\n\"git reset\" will update ORIG_HEAD to the current HEAD before resetting \nso here ORIG_HEAD gets updated to point to XYZ\n\n> 4. git-commit -C ORIG_HEAD -a\n> 5. git-rebase --continue\n> 6. git-show ORIG_HEAD\n> \n> Expected behavior:\n> ORIG_HEAD should point at the previous HEAD of the rebased branch\n> \n> Actual behavior:\n> ORIG_HEAD points to XYZ\n> \n> My understanding from reading https://stackoverflow.com/a/64949884 is\n> that this is incorrect behavior.\n> \n> Perhaps this is as intended but I would at least personally prefer\n> that ORIG_HEAD would point to the previous HEAD of the rebased branch.\n\nYou can use the reflog to get the previous HEAD of the rebased branch \nafter rebasing. Immediately after the rebase branch-name@{1} will point \nto the pre-rebase HEAD.\n\nBest Wishes\n\nPhillip\n\n\n> Seen in:\n> git version 2.31.1.windows.1\n> \n> Possibly related to\n> e100bea481 - rebase -i: stop overwriting ORIG_HEAD buffer\n\n"},{"id":"444241","messageId":"CA+JQ7M9G8HqqieRAK3C6csMM93PHOmaMd8GMPrDEfogWG0bteA@mail.gmail.com","threadId":"57092","inReplyTo":"e6adaad6-f6ee-57d3-dc8f-d14a760c57c2@talktalk.net","subject":"Re: bug?: ORIG_HEAD incorrect after reset during git-rebase -i","fromName":"Erik Cervin Edin","fromEmail":"erik@cervined.in","sentAt":"2021-12-16T16:44:02Z","receivedAt":"2021-12-16T16:44:39Z","isPatch":false,"sender":{"key":"erik@cervined.in","avatar":null},"body":"Hi Phillip,\n\nYes, I know.\nIt's just that I was under the impression ORIG_HEAD was to be reverted\nto .git/rebase-merge/orig-head at the finish of the rebase.\nPersonally, it's the behavior I would expect.\n\nThanks for the tips.\n\nRegards,\nErik\n\nOn Thu, Dec 16, 2021 at 5:27 PM Phillip Wood <phillip.wood@talktalk.net> wrote:\n>\n> Hi Erik\n>\n> On 16/12/2021 14:30, Erik Cervin Edin wrote:\n> > Steps to reproduce:\n> > 1. git-rebase -i\n> > 2. edit XYZ\n> > 3. git-reset HEAD~\n>\n> \"git reset\" will update ORIG_HEAD to the current HEAD before resetting\n> so here ORIG_HEAD gets updated to point to XYZ\n>\n> > 4. git-commit -C ORIG_HEAD -a\n> > 5. git-rebase --continue\n> > 6. git-show ORIG_HEAD\n> >\n> > Expected behavior:\n> > ORIG_HEAD should point at the previous HEAD of the rebased branch\n> >\n> > Actual behavior:\n> > ORIG_HEAD points to XYZ\n> >\n> > My understanding from reading https://stackoverflow.com/a/64949884 is\n> > that this is incorrect behavior.\n> >\n> > Perhaps this is as intended but I would at least personally prefer\n> > that ORIG_HEAD would point to the previous HEAD of the rebased branch.\n>\n> You can use the reflog to get the previous HEAD of the rebased branch\n> after rebasing. Immediately after the rebase branch-name@{1} will point\n> to the pre-rebase HEAD.\n>\n> Best Wishes\n>\n> Phillip\n>\n>\n> > Seen in:\n> > git version 2.31.1.windows.1\n> >\n> > Possibly related to\n> > e100bea481 - rebase -i: stop overwriting ORIG_HEAD buffer\n>\n\n\n-- \nErik Cervin-Edin\nErik.CervinEd.in\n"},{"id":"469801","messageId":"ef389a14-8513-4650-21e4-89421a24df2d@gmail.com","threadId":"57092","inReplyTo":"CA+JQ7M9G8HqqieRAK3C6csMM93PHOmaMd8GMPrDEfogWG0bteA@mail.gmail.com","subject":"Re: bug?: ORIG_HEAD incorrect after reset during git-rebase -i","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2023-01-05T00:11:42Z","receivedAt":"2023-01-05T00:14:04Z","isPatch":false,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hi Phillip and Erik,\n\nLe 2021-12-16 à 11:44, Erik Cervin Edin a écrit :\n> Hi Phillip,\n> \n> Yes, I know.\n> It's just that I was under the impression ORIG_HEAD was to be reverted\n> to .git/rebase-merge/orig-head at the finish of the rebase.\n> Personally, it's the behavior I would expect.\n> \n> Thanks for the tips.\n\nI just hit the same bug (I think it qualifies as one). In fact git-rebase(1) explicitely mentions\nthat ORIG_HEAD is set to the branch tip before the rebase starts:\n\n$ git grep -C2 ORIG_HEAD Documentation/git-rebase.txt\nDocumentation/git-rebase.txt-36-The current branch is reset to `<upstream>` or `<newbase>` if the\nDocumentation/git-rebase.txt-37-`--onto` option was supplied.  This has the exact same effect as\nDocumentation/git-rebase.txt:38:50:`git reset --hard <upstream>` (or `<newbase>`). `ORIG_HEAD` is set\nDocumentation/git-rebase.txt-39-to point at the tip of the branch before the reset.\nDocumentation/git-rebase.txt-40-\n\nHere is my runnable reproducer. It is slightly more complicated than Erik's, since\nI split the second commit in two, but this is not necessary to trigger the bug; just\nrunning 'git reset HEAD^' as Erik wrote is enough.\n\n```bash\n#!/bin/bash\nrm -rf repro\ngit init repro\n(\ncd repro\n# Create 3 commits\ncat << EOF >test\nhello\nevery\none\nEOF\ngit add test\ngit commit -m initial\ncat << EOF >test\nhello\n\nadd new lines\n\nevery\n\nand also here\n\none\nEOF\ngit commit -am second\ncat << EOF >test\nhello\n\nadd new lines\n\nevery\n\nand also here\n\none\n\nstill more changes\nEOF\ngit commit -am third\n# Rebase to split the second commit\nGIT_SEQUENCE_EDITOR=\"sed -ie '1 s/^p /e /'\" git rebase -i HEAD~2\ngit reset HEAD^\ncat << EOF >test\nhello\n\nadd new lines\n\nevery\none\nEOF\ngit ci -am \"second 1/2\"\ncat <<EOF >test\nhello\n\nadd new lines\n\nevery\n\nand also here\n\none\nEOF\ngit ci -am \"second 2/2\"\n# Finish rebase and demonstrate bug\ngit rebase --continue\necho ---\necho \"@{1} is :\"\ngit log -1 @{1}\necho \"ORIG_HEAD is :\"\ngit log -1 ORIG_HEAD\n\n)\n```\n\nCheers,\n\nPhilippe.\n"},{"id":"469835","messageId":"81218256-5354-4b0a-6f74-7e9605131968@dunelm.org.uk","threadId":"57092","inReplyTo":"ef389a14-8513-4650-21e4-89421a24df2d@gmail.com","subject":"Re: bug?: ORIG_HEAD incorrect after reset during git-rebase -i","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2023-01-06T14:29:19Z","receivedAt":"2023-01-06T14:30:25Z","isPatch":false,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Philippe & Erik\n\nOn 05/01/2023 00:11, Philippe Blain wrote:\n> Hi Phillip and Erik,\n> \n> Le 2021-12-16 à 11:44, Erik Cervin Edin a écrit :\n>> Hi Phillip,\n>>\n>> Yes, I know.\n>> It's just that I was under the impression ORIG_HEAD was to be reverted\n>> to .git/rebase-merge/orig-head at the finish of the rebase.\n>> Personally, it's the behavior I would expect.\n>>\n>> Thanks for the tips.\n> \n> I just hit the same bug (I think it qualifies as one). In fact git-rebase(1) explicitely mentions\n> that ORIG_HEAD is set to the branch tip before the rebase starts:\n\nStrictly speaking that is what we do so we're documentation the \nimplemented behavior. What's not clear from the documentation is that if \nthe user run 'git reset' while rebasing then ORIG_HEAD will be \noverwritten. We could update ORIG_HEAD at the end of the rebase as you \nsuggested but I wouldn't be surprised if some else complains that \nORIG_HEAD no longer points to the commit that the reset while running \nrebase. I also wonder if users would expect 'git rebase --continue' to \nupdate ORIG_HEAD to point to the pre-rebase HEAD so it is consistent \neach time rebase stops. Basically I think the situation is confusing and \nI don't have a clear idea as to how to make it better. If someone \nsubmits a patch to try and clean things up I'll happily look at it but \nunless I'm hit by a bright idea as to how to fix it I probably wont work \non it myself.\n\nBest Wishes\n\nPhillip\n\n> $ git grep -C2 ORIG_HEAD Documentation/git-rebase.txt\n> Documentation/git-rebase.txt-36-The current branch is reset to `<upstream>` or `<newbase>` if the\n> Documentation/git-rebase.txt-37-`--onto` option was supplied.  This has the exact same effect as\n> Documentation/git-rebase.txt:38:50:`git reset --hard <upstream>` (or `<newbase>`). `ORIG_HEAD` is set\n> Documentation/git-rebase.txt-39-to point at the tip of the branch before the reset.\n> Documentation/git-rebase.txt-40-\n> \n> Here is my runnable reproducer. It is slightly more complicated than Erik's, since\n> I split the second commit in two, but this is not necessary to trigger the bug; just\n> running 'git reset HEAD^' as Erik wrote is enough.\n> \n> ```bash\n> #!/bin/bash\n> rm -rf repro\n> git init repro\n> (\n> cd repro\n> # Create 3 commits\n> cat << EOF >test\n> hello\n> every\n> one\n> EOF\n> git add test\n> git commit -m initial\n> cat << EOF >test\n> hello\n> \n> add new lines\n> \n> every\n> \n> and also here\n> \n> one\n> EOF\n> git commit -am second\n> cat << EOF >test\n> hello\n> \n> add new lines\n> \n> every\n> \n> and also here\n> \n> one\n> \n> still more changes\n> EOF\n> git commit -am third\n> # Rebase to split the second commit\n> GIT_SEQUENCE_EDITOR=\"sed -ie '1 s/^p /e /'\" git rebase -i HEAD~2\n> git reset HEAD^\n> cat << EOF >test\n> hello\n> \n> add new lines\n> \n> every\n> one\n> EOF\n> git ci -am \"second 1/2\"\n> cat <<EOF >test\n> hello\n> \n> add new lines\n> \n> every\n> \n> and also here\n> \n> one\n> EOF\n> git ci -am \"second 2/2\"\n> # Finish rebase and demonstrate bug\n> git rebase --continue\n> echo ---\n> echo \"@{1} is :\"\n> git log -1 @{1}\n> echo \"ORIG_HEAD is :\"\n> git log -1 ORIG_HEAD\n> \n> )\n> ```\n> \n> Cheers,\n> \n> Philippe.\n"},{"id":"469882","messageId":"1b2b8e98-5506-a1e6-6059-a967757b3bb8@gmail.com","threadId":"57092","inReplyTo":"81218256-5354-4b0a-6f74-7e9605131968@dunelm.org.uk","subject":"Re: bug?: ORIG_HEAD incorrect after reset during git-rebase -i","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2023-01-07T17:06:15Z","receivedAt":"2023-01-07T17:06:23Z","isPatch":false,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"\nHi Phillip,\n\nLe 2023-01-06 à 09:29, Phillip Wood a écrit :\n> Hi Philippe & Erik\n> \n> On 05/01/2023 00:11, Philippe Blain wrote:\n>> Hi Phillip and Erik,\n>>\n>> Le 2021-12-16 à 11:44, Erik Cervin Edin a écrit :\n>>> Hi Phillip,\n>>>\n>>> Yes, I know.\n>>> It's just that I was under the impression ORIG_HEAD was to be reverted\n>>> to .git/rebase-merge/orig-head at the finish of the rebase.\n>>> Personally, it's the behavior I would expect.\n>>>\n>>> Thanks for the tips.\n>>\n>> I just hit the same bug (I think it qualifies as one). In fact git-rebase(1) explicitely mentions\n>> that ORIG_HEAD is set to the branch tip before the rebase starts:\n> \n> Strictly speaking that is what we do so we're documentation the\n> implemented behavior. What's not clear from the documentation is that\n> if the user run 'git reset' while rebasing then ORIG_HEAD will be\n> overwritten. \n\nYes, I agree. I think we could highlight it in the doc.\n\n> We could update ORIG_HEAD at the end of the rebase as\n> you suggested but I wouldn't be surprised if some else complains that\n> ORIG_HEAD no longer points to the commit that the reset while running\n> rebase. I also wonder if users would expect 'git rebase --continue'\n> to update ORIG_HEAD to point to the pre-rebase HEAD so it is\n> consistent each time rebase stops. Basically I think the situation is\n> confusing and I don't have a clear idea as to how to make it better.\n> If someone submits a patch to try and clean things up I'll happily\n> look at it but unless I'm hit by a bright idea as to how to fix it I\n> probably wont work on it myself.\n\nThanks for your thoughts. I think you make good points, it's true that \nsome people might be relying on the current behaviour.\n\nI'll try to send a few updates to the doc to make this hopefully clearer.\n\nCheers,\nPhilippe.\n"},{"id":"469892","messageId":"28ebf03b-e8bb-3769-556b-c9db17e43dbb@gmail.com","threadId":"57092","inReplyTo":"1b2b8e98-5506-a1e6-6059-a967757b3bb8@gmail.com","subject":"Re: bug?: ORIG_HEAD incorrect after reset during git-rebase -i","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2023-01-07T19:50:45Z","receivedAt":"2023-01-07T19:50:53Z","isPatch":false,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Le 2023-01-07 à 12:06, Philippe Blain a écrit :\n> \n> Hi Phillip,\n> \n> I'll try to send a few updates to the doc to make this hopefully clearer.\n\nSee https://lore.kernel.org/git/pull.1456.git.1673120359.gitgitgadget@gmail.com/T/#t\n"}]}