git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: minor interactive rebase regression: HEAD points to wrong commit while rewording

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Aug 14, 2019, 20:45 UTC
Message-ID
<nycvar.QRO.7.76.6.1908142241080.656@tvgsbejvaqbjf.bet>
In-Reply-To
<2a7d69a9-cb3e-eb84-188f-5713876f6d78@gmail.com>
Hi,
On Mon, 12 Aug 2019, Phillip Wood wrote:
Show 53 quoted lines
> 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.
Show 6 quoted 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_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

Previous: Phillip WoodNext: SZEDER Gábor
Message 5 of 10 in “minor interactive rebase regression: HEAD points to wrong commit while rewording”
  1. SZEDER GáborAug 12, 2019
  2. Junio C HamanoAug 12, 2019
  3. SZEDER GáborAug 12, 2019
  4. Phillip WoodAug 12, 2019
  5. Johannes SchindelinAug 14, 2019
  6. SZEDER GáborAug 14, 2019
  7. SZEDER GáborAug 14, 2019
  8. Phillip WoodAug 15, 2019
  9. Junio C HamanoAug 15, 2019
  10. Junio C HamanoAug 15, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.