minor interactive rebase regression: HEAD points to wrong commit while rewording
When running interactive rebase to reword a commit message, I would expect that the commit whose message I'm rewording is checked out. This is not quite the case when rewording multiple subsequent commit messages.
Let's start with four commits, and start an interactive rebase from the first commit:
$ git log --oneline 5835aa1 (HEAD -> master) fourth 64ecc64 third d5fad83 second 384b86f first $ git rebase -i 384b86f
Update the instruction sheet to edit the log messages of two subsequent commits:
r d5fad83 second
r 64ecc64 third
pick 5835aa1 fourth
Now, after the editor opens up the second commit's log message, start a new terminal and check where HEAD is pointing to:
~/tmp/reword (master|REBASE-i 1/3)$ head -n1 .git/COMMIT_EDITMSG second ~/tmp/reword (master|REBASE-i 1/3)$ git log --oneline -1 d5fad83 (HEAD) second
So far so good.
Save the updated commit message, and after the editor opens up the third commit's log message, check again where HEAD is pointing to now:
~/tmp/reword (master +|REBASE-i 2/3)$ head -n1 .git/COMMIT_EDITMSG third ~/tmp/reword (master +|REBASE-i 2/3)$ git log --oneline -1 c3db735 (HEAD) second - updated
As you can see, HEAD still points to the (now rewritten) second commit.
It's only HEAD, though: notice the '+' in the git prompt, indicating that both the worktree and index are dirty. And indeed, they both already match the state of the currently reworded, i.e. third, commit:
~/tmp/reword (master +|REBASE-i 2/3)$ cat file
third
This is good, because even though HEAD has not been updated yet, it already allows users to take a look at the "big picture", i.e. actual file contents, in case the diff included in the commit message template doesn't show enough context.
This behavior changed in commit 18633e1a22 (rebase -i: use the rebase--helper builtin, 2017-02-09); prior to that HEAD pointed to the third commit while editing its log message.
It's important to reword subsequent commits. When rewording multiple, but non subsequent commits (e.g. reword, pick, reword in the instruction sheet), then HEAD is pointing to the right commits during both rewords.
Quoted 10 lines · SZEDER Gábor
...
So far so good.
Save the updated commit message, and after the editor opens up the third commit's log message, check again where HEAD is pointing to now:~/tmp/reword (master +|REBASE-i 2/3)$ head -n1 .git/COMMIT_EDITMSG third ~/tmp/reword (master +|REBASE-i 2/3)$ git log --oneline -1 c3db735 (HEAD) second - updated
Quoted 4 lines
As you can see, HEAD still points to the (now rewritten) second commit.
It's only HEAD,...
Yuck.
That would still be annoying to some people and outright buggy to others, if their workflow relies on HEAD (e.g. compare with HEAD while reviewing the log messsage) and then now they instead need to adjust (e.g. compare with the index instead). Perhaps you are one of them (apparently I am not, as I did not notice the behaviour change until you pointed it out here).
Quoted 15 lines · Junio C Hamano
Quoted 13 lines · SZEDER Gábor
...
So far so good.
Save the updated commit message, and after the editor opens up the third commit's log message, check again where HEAD is pointing to now:~/tmp/reword (master +|REBASE-i 2/3)$ head -n1 .git/COMMIT_EDITMSG third ~/tmp/reword (master +|REBASE-i 2/3)$ git log --oneline -1 c3db735 (HEAD) second - updatedAs you can see, HEAD still points to the (now rewritten) second commit.
Quoted 8 lines
Quoted 1 line
It's only HEAD,...
Yuck.
That would still be annoying to some people and outright buggy to others, if their workflow relies on HEAD (e.g. compare with HEAD while reviewing the log messsage) and then now they instead need to adjust (e.g. compare with the index instead).
Well, it's caused by a 2.5 year old commit, so either all those people have been lucky so far (or just don't do subsequent rewords?), or those who stumbled upon it already adjusted without complaining to us.
Quoted 1 line
Perhaps you are one of them
No; during the second reword I ran 'git log -2' in the other terminal (wanted to copy a sentence from the previous, just reworded commit), and noticed that the two listed commits were "off by one".
BTW, rewriting the first commit appears to be important. When doing an edit-reword of two subsequent commits, then this issue only happens if the edit actually rewrites the commit. However, when, instead of editing anything, I do a 'git rebase --continue' right away, then HEAD points to where it should during the subsequent reword.
Anyway, Cc:-ing Dscho for his rebase expertise.
Quoted 26 lines · SZEDER Gábor
When running interactive rebase to reword a commit message, I would expect that the commit whose message I'm rewording is checked out. This is not quite the case when rewording multiple subsequent commit messages.
Let's start with four commits, and start an interactive rebase from the first commit:
$ git log --oneline 5835aa1 (HEAD -> master) fourth 64ecc64 third d5fad83 second 384b86f first $ git rebase -i 384b86fUpdate the instruction sheet to edit the log messages of two subsequent commits:
r d5fad83 second r 64ecc64 third pick 5835aa1 fourthNow, after the editor opens up the second commit's log message, start a new terminal and check where HEAD is pointing to:
Quoted 6 lines
~/tmp/reword (master|REBASE-i 1/3)$ head -n1 .git/COMMIT_EDITMSG second ~/tmp/reword (master|REBASE-i 1/3)$ git log --oneline -1 d5fad83 (HEAD) secondSo far so good.
Because the sequencer can fast-forwarded to second from first it does that and then run 'commit --amend' to do the reword.
Quoted 7 lines
Save the updated commit message, and after the editor opens up the third commit's log message, check again where HEAD is pointing to now:
~/tmp/reword (master +|REBASE-i 2/3)$ head -n1 .git/COMMIT_EDITMSG third ~/tmp/reword (master +|REBASE-i 2/3)$ git log --oneline -1 c3db735 (HEAD) second - updated
As second has been updated the sequencer cannot fast-forward to third so it cherry-picks third and then passes --edit when it runs 'git commit' to commit the cherry-pick. HEAD is updated once the reworded commit has been created.
I think the scripted rebase always ran cherry-pick and then ran 'commit --amend' afterwards if the commit was being reworded. The C implementation is more efficient as it avoids creating an redundant commit but has the side effect that HEAD is not updated before the reword which was surprising here.
I don't think I've ever looked at HEAD while rewording, my shell prompt gets the current pick from .git/rebase-merge/done so does not look at HEAD. While it might seem odd if the user looks at HEAD it's quite nice not to create a new commit only to amend it straight away when it's reworded. We have REBASE_HEAD which always points to the current pick - HEAD is also an unreliable indicator of the current pick if there are conflicts.
Best Wishes
Phillip
Quoted 25 lines
As you can see, HEAD still points to the (now rewritten) second commit.
It's only HEAD, though: notice the '+' in the git prompt, indicating that both the worktree and index are dirty. And indeed, they both already match the state of the currently reworded, i.e. third, commit:
~/tmp/reword (master +|REBASE-i 2/3)$ cat file thirdThis is good, because even though HEAD has not been updated yet, it already allows users to take a look at the "big picture", i.e. actual file contents, in case the diff included in the commit message template doesn't show enough context.
This behavior changed in commit
18633e1a22(rebase -i: use the rebase--helper builtin, 2017-02-09); prior to that HEAD pointed to the third commit while editing its log message.It's important to reword subsequent commits. When rewording multiple, but non subsequent commits (e.g. reword, pick, reword in the instruction sheet), then HEAD is pointing to the right commits during both rewords.
Hi,
Quoted 45 lines · Phillip Wood
Quoted 26 lines · SZEDER Gábor
When running interactive rebase to reword a commit message, I would expect that the commit whose message I'm rewording is checked out. This is not quite the case when rewording multiple subsequent commit messages.
Let's start with four commits, and start an interactive rebase from the first commit:
$ git log --oneline 5835aa1 (HEAD -> master) fourth 64ecc64 third d5fad83 second 384b86f first $ git rebase -i 384b86fUpdate the instruction sheet to edit the log messages of two subsequent commits:
r d5fad83 second r 64ecc64 third pick 5835aa1 fourthNow, after the editor opens up the second commit's log message, start a new terminal and check where HEAD is pointing to:
Quoted 6 lines
~/tmp/reword (master|REBASE-i 1/3)$ head -n1 .git/COMMIT_EDITMSG second ~/tmp/reword (master|REBASE-i 1/3)$ git log --oneline -1 d5fad83 (HEAD) secondSo far so good.
Because the sequencer can fast-forwarded to second from first it does that and then run 'commit --amend' to do the reword.
Quoted 7 lines
Save the updated commit message, and after the editor opens up the third commit's log message, check again where HEAD is pointing to now:
~/tmp/reword (master +|REBASE-i 2/3)$ head -n1 .git/COMMIT_EDITMSG third ~/tmp/reword (master +|REBASE-i 2/3)$ git log --oneline -1 c3db735 (HEAD) second - updated
Quoted 8 lines
As second has been updated the sequencer cannot fast-forward to third so it cherry-picks third and then passes --edit when it runs 'git commit' to commit the cherry-pick. HEAD is updated once the reworded commit has been created.
I think the scripted rebase always ran cherry-pick and then ran 'commit --amend' afterwards if the commit was being reworded. The C implementation is more efficient as it avoids creating an redundant commit but has the side effect that HEAD is not updated before the reword which was surprising here.
Indeed, that was even intentional.
Quoted 6 lines
I don't think I've ever looked at HEAD while rewording, my shell prompt gets the current pick from .git/rebase-merge/done so does not look at HEAD. While it might seem odd if the user looks at HEAD it's quite nice not to create a new commit only to amend it straight away when it's reworded. We have
REBASE_HEADwhich always points to the current pick - HEAD is also an unreliable indicator of the current pick if there are conflicts.
That is interesting; I would never have thought about scripting around reword.
However, I am reluctant to accept the performance impact: in the long run, I would love to have an interactive rebase that actually only updates HEAD (and the worktree) when interrupting the rebase (via break or edit), and reword does not qualify for "interrupting" in my mind.
Ciao,
Dscho
Quoted 5 lines · Johannes Schindelin
However, I am reluctant to accept the performance impact: in the long run, I would love to have an interactive rebase that actually only updates
HEAD(and the worktree) when interrupting the rebase (viabreakoredit), andreworddoes not qualify for "interrupting" in my mind.
It's crucial that users can look at the files in the currently reworded commit while it is being reworded.
Quoted 13 lines · Phillip Wood
Quoted 7 lines
Save the updated commit message, and after the editor opens up the third commit's log message, check again where HEAD is pointing to now:
~/tmp/reword (master +|REBASE-i 2/3)$ head -n1 .git/COMMIT_EDITMSG third ~/tmp/reword (master +|REBASE-i 2/3)$ git log --oneline -1 c3db735 (HEAD) second - updatedAs second has been updated the sequencer cannot fast-forward to third so it cherry-picks third and then passes --edit when it runs 'git commit' to commit the cherry-pick. HEAD is updated once the reworded commit has been created.
Quoted 4 lines
I think the scripted rebase always ran cherry-pick and then ran 'commit --amend' afterwards if the commit was being reworded. The C implementation is more efficient as it avoids creating an redundant commit but has the side effect that HEAD is not updated before the reword which was surprising here.
I'm not sure about this more efficient thing. I mean, 'git rebase' is about to launch the editor to let the user type something... Compared to that the time spent in creating an extra commit object is surely negligible.
Quoted 19 lines · SZEDER Gábor
Quoted 13 lines · Phillip Wood
Quoted 7 lines
Save the updated commit message, and after the editor opens up the third commit's log message, check again where HEAD is pointing to now:
~/tmp/reword (master +|REBASE-i 2/3)$ head -n1 .git/COMMIT_EDITMSG third ~/tmp/reword (master +|REBASE-i 2/3)$ git log --oneline -1 c3db735 (HEAD) second - updatedAs second has been updated the sequencer cannot fast-forward to third so it cherry-picks third and then passes --edit when it runs 'git commit' to commit the cherry-pick. HEAD is updated once the reworded commit has been created.
Quoted 4 lines
I think the scripted rebase always ran cherry-pick and then ran 'commit --amend' afterwards if the commit was being reworded. The C implementation is more efficient as it avoids creating an redundant commit but has the side effect that HEAD is not updated before the reword which was surprising here.
Quoted 4 lines
I'm not sure about this more efficient thing. I mean, 'git rebase' is about to launch the editor to let the user type something... Compared to that the time spent in creating an extra commit object is surely negligible.
I changed the sequencer to always commit the cherry-pick and then run 'git commit --amend' for rewords [1]. Running
time env GIT_EDITOR=true GIT_SEQUENCE_EDITOR='sed -i s/pick/reword/'
../bin-wrappers/git rebase -i --root
over 100 commits I cannot see any real difference in the timings between master and that branch. Any difference is within the variation of the times of multiple runs. The change also fixes a bug when rewording a re-arranged root commit.
Best Wishes
Phillip
[1] https://github.com/phillipwood/git/commits/wip/rebase-reword-update-head
Quoted 5 lines · Phillip Wood
On 14/08/2019 22:20, SZEDER Gábor wrote:
I changed the sequencer to always commit the cherry-pick and then run 'git commit --amend' for rewords [1]. Running
Quoted 7 lines
time env GIT_EDITOR=true GIT_SEQUENCE_EDITOR='sed -i
s/pick/reword/' ../bin-wrappers/git rebase -i --rootover 100 commits I cannot see any real difference in the timings between master and that branch. Any difference is within the variation of the times of multiple runs. The change also fixes a bug when rewording a re-arranged root commit.
I guess that settles the "efficiency" story; besides, showing a wrong intermediate state to users and scripts efficiently is just as bad as showing a wrong state less efficiently.
Quoted 10 lines · Junio C Hamano
Quoted 8 lines · Phillip Wood
On 14/08/2019 22:20, SZEDER Gábor wrote:
I changed the sequencer to always commit the cherry-pick and then run 'git commit --amend' for rewords [1]. Running
time env GIT_EDITOR=true GIT_SEQUENCE_EDITOR='sed -i
s/pick/reword/' ../bin-wrappers/git rebase -i --root
Quoted 8 lines
Quoted 4 lines
over 100 commits I cannot see any real difference in the timings between master and that branch. Any difference is within the variation of the times of multiple runs. The change also fixes a bug when rewording a re-arranged root commit.
I guess that settles the "efficiency" story; besides, showing a wrong intermediate state to users and scripts efficiently is just as bad as showing a wrong state less efficiently.
Needless to say, there is no need for us to make things less efficient when we do not need to. If there are two back-to-back "pick"s, and there is no hook and the like that gives an end-user and/or a script a reliable trigger point that can be used to "observe" and "utilize" the state immediately after the first "pick", we do not have to update the HEAD (or update the working tree for that matter) between these two "pick"s.
The external process being able to observe alone is not an enough reason to force us go inefficient here---if the triggering event is like "spawn an editor and wait for it to exit", that gives the external process to not just "observe" the updated state after the first pick, but also "utilize" that state (e.g. build, compare with some other tree, etc.) knowing that the second "pick" does not start changing the state until it relinquishes the control.
But unless the external process can reliably utilize the updated state, it is of not much use to just be able to notice the change. For example, an argument like "constantly monitoring changes in the $GIT_DIR/rebase-merge directory, we can notice that each 'pick' gets done" is not a reason to force us to update HEAD every time any instruction is consumed in the todo file, as the next "pick" cannot be reliably delayed by somebody who is merely observing the directory to utilize the updated state.