git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* minor interactive rebase regression: HEAD points to wrong commit while rewording
@ 2019-08-12 17:50 SZEDER Gábor
  2019-08-12 18:17 ` Junio C Hamano
  2019-08-12 20:28 ` Phillip Wood
  0 siblings, 2 replies; 10+ messages in thread
From: SZEDER Gábor @ 2019-08-12 17:50 UTC (permalink / raw)
  To: git


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.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: minor interactive rebase regression: HEAD points to wrong commit while rewording
  2019-08-12 17:50 minor interactive rebase regression: HEAD points to wrong commit while rewording SZEDER Gábor
@ 2019-08-12 18:17 ` Junio C Hamano
  2019-08-12 18:56   ` SZEDER Gábor
  2019-08-12 20:28 ` Phillip Wood
  1 sibling, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2019-08-12 18:17 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: git

SZEDER Gábor <szeder.dev@gmail.com> writes:

> ...
> 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,...

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).


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: minor interactive rebase regression: HEAD points to wrong commit while rewording
  2019-08-12 18:17 ` Junio C Hamano
@ 2019-08-12 18:56   ` SZEDER Gábor
  0 siblings, 0 replies; 10+ messages in thread
From: SZEDER Gábor @ 2019-08-12 18:56 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Johannes Schindelin

On Mon, Aug 12, 2019 at 11:17:01AM -0700, Junio C Hamano wrote:
> SZEDER Gábor <szeder.dev@gmail.com> writes:
> 
> > ...
> > 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,...
> 
> 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.

> 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.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: minor interactive rebase regression: HEAD points to wrong commit while rewording
  2019-08-12 17:50 minor interactive rebase regression: HEAD points to wrong commit while rewording SZEDER Gábor
  2019-08-12 18:17 ` Junio C Hamano
@ 2019-08-12 20:28 ` Phillip Wood
  2019-08-14 20:45   ` Johannes Schindelin
  2019-08-14 21:20   ` SZEDER Gábor
  1 sibling, 2 replies; 10+ messages in thread
From: Phillip Wood @ 2019-08-12 20:28 UTC (permalink / raw)
  To: SZEDER Gábor, git; +Cc: Junio C Hamano, Johannes Schindelin

On 12/08/2019 18:50, SZEDER Gábor wrote:
> 
> 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.

Because the sequencer can fast-forwarded to second from first it does 
that and then run 'commit --amend' to do the reword.

> 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

> 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.
> 
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: minor interactive rebase regression: HEAD points to wrong commit while rewording
  2019-08-12 20:28 ` Phillip Wood
@ 2019-08-14 20:45   ` Johannes Schindelin
  2019-08-14 21:40     ` SZEDER Gábor
  2019-08-14 21:20   ` SZEDER Gábor
  1 sibling, 1 reply; 10+ messages in thread
From: Johannes Schindelin @ 2019-08-14 20:45 UTC (permalink / raw)
  To: Phillip Wood; +Cc: SZEDER Gábor, git, Junio C Hamano

[-- Attachment #1: Type: text/plain, Size: 3066 bytes --]

Hi,

On Mon, 12 Aug 2019, Phillip Wood wrote:

> On 12/08/2019 18:50, SZEDER Gábor wrote:
> >
> > 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.
>
> Because the sequencer can fast-forwarded to second from first it does that and
> then run 'commit --amend' to do the reword.
>
> > 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.

Indeed, that was even intentional.

> 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.

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: minor interactive rebase regression: HEAD points to wrong commit while rewording
  2019-08-12 20:28 ` Phillip Wood
  2019-08-14 20:45   ` Johannes Schindelin
@ 2019-08-14 21:20   ` SZEDER Gábor
  2019-08-15 13:47     ` Phillip Wood
  1 sibling, 1 reply; 10+ messages in thread
From: SZEDER Gábor @ 2019-08-14 21:20 UTC (permalink / raw)
  To: Phillip Wood; +Cc: git, Junio C Hamano, Johannes Schindelin

On Mon, Aug 12, 2019 at 09:28:52PM +0100, Phillip Wood wrote:
> >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'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.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: minor interactive rebase regression: HEAD points to wrong commit while rewording
  2019-08-14 20:45   ` Johannes Schindelin
@ 2019-08-14 21:40     ` SZEDER Gábor
  0 siblings, 0 replies; 10+ messages in thread
From: SZEDER Gábor @ 2019-08-14 21:40 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Phillip Wood, git, Junio C Hamano

On Wed, Aug 14, 2019 at 10:45:22PM +0200, Johannes Schindelin wrote:
> 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.

It's crucial that users can look at the files in the currently
reworded commit while it is being reworded.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: minor interactive rebase regression: HEAD points to wrong commit while rewording
  2019-08-14 21:20   ` SZEDER Gábor
@ 2019-08-15 13:47     ` Phillip Wood
  2019-08-15 16:36       ` Junio C Hamano
  0 siblings, 1 reply; 10+ messages in thread
From: Phillip Wood @ 2019-08-15 13:47 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: git, Junio C Hamano, Johannes Schindelin

On 14/08/2019 22:20, SZEDER Gábor wrote:
> On Mon, Aug 12, 2019 at 09:28:52PM +0100, Phillip Wood wrote:
>>> 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'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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: minor interactive rebase regression: HEAD points to wrong commit while rewording
  2019-08-15 13:47     ` Phillip Wood
@ 2019-08-15 16:36       ` Junio C Hamano
  2019-08-15 16:54         ` Junio C Hamano
  0 siblings, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2019-08-15 16:36 UTC (permalink / raw)
  To: Phillip Wood; +Cc: SZEDER Gábor, git, Johannes Schindelin

Phillip Wood <phillip.wood123@gmail.com> writes:

> 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
>
> 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.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: minor interactive rebase regression: HEAD points to wrong commit while rewording
  2019-08-15 16:36       ` Junio C Hamano
@ 2019-08-15 16:54         ` Junio C Hamano
  0 siblings, 0 replies; 10+ messages in thread
From: Junio C Hamano @ 2019-08-15 16:54 UTC (permalink / raw)
  To: Phillip Wood; +Cc: SZEDER Gábor, git, Johannes Schindelin

Junio C Hamano <gitster@pobox.com> writes:

> Phillip Wood <phillip.wood123@gmail.com> writes:
>
>> 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
>>
>> 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.



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-08-15 16:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-12 17:50 minor interactive rebase regression: HEAD points to wrong commit while rewording SZEDER Gábor
2019-08-12 18:17 ` Junio C Hamano
2019-08-12 18:56   ` SZEDER Gábor
2019-08-12 20:28 ` Phillip Wood
2019-08-14 20:45   ` Johannes Schindelin
2019-08-14 21:40     ` SZEDER Gábor
2019-08-14 21:20   ` SZEDER Gábor
2019-08-15 13:47     ` Phillip Wood
2019-08-15 16:36       ` Junio C Hamano
2019-08-15 16:54         ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).