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.