git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "SZEDER Gábor" <szeder.dev@gmail.com>
To: git@vger.kernel.org
Subject: minor interactive rebase regression: HEAD points to wrong commit while rewording
Date: Mon, 12 Aug 2019 19:50:46 +0200	[thread overview]
Message-ID: <20190812175046.GM20404@szeder.dev> (raw)


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.



             reply	other threads:[~2019-08-12 17:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-12 17:50 SZEDER Gábor [this message]
2019-08-12 18:17 ` minor interactive rebase regression: HEAD points to wrong commit while rewording 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190812175046.GM20404@szeder.dev \
    --to=szeder.dev@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).