I\'m currently in the midst of a git rebase --interactive
session, where I\'m editing a commit. I\'m proceeding as suggested by How can I split up a Git commit bur
Why follow instructions on commit splitting if you don't want it?
You don't reset to HEAD^
, this applies only when splitting commits. Just mark the commit for editing in rebase -i
, make your changes, commit --amend
and rebase --continue
.
While CharlesB's solution is correct and probably easier, the reason that the original poster is seeing the commit message before the commit he wants to edit is because he's using the --amend
flag of git commit
, which modifies the previous commit.
Instead of using --amend
to commit your changes, just use git commit
without the flag, which won't touch the previous commit. You can also pass in an option to reuse the commit message from the commit that you reset using git reset head^
:
git commit --reuse-message=HEAD@{1}
# Or use -C, which is the same thing, but shorter:
git commit -C HEAD@{1}
HEAD@{1}
points to the commit you were at before you did git reset head^
. You can also just pass in the sha id for that commit directly.
From the git commit docs:
-C <commit> --reuse-message=<commit>
Take an existing commit object, and reuse the log message and the authorship information (including the timestamp) when creating the commit.
Of course, like I said, CharlesB's solution is simpler, since if you don't do the first git reset head^
, you can just make changes and amend the commit you're trying to modify directly, and you automatically get the previous commit message when you do git commit --amend
, you don't have to pass in the commit sha for it.
I have another answer that seems to be more fool-proof, though undocumented.
$ git reset HEAD^
$ git add ... # stage the first part of your split
$ git commit -m 'part one'
$ git commit -a -F $(git rev-parse --git-dir)/rebase-merge/message
I adapted some examples in git-commit(1) and git-reset(1):
$ git reset HEAD^
$ git add ... # stage the first part of your split
$ git commit -m 'part one'
$ git commit -a -c ORIG_HEAD # start with the earlier commit message
If you're worried about doing something that might change ORIG_HEAD
, you could instead do:
$ SAVED=$(git rev-parse HEAD)
$ git reset HEAD^
...
$ git commit -a -c $SAVED # start with the earlier commit message