How do I keep the commit message when editing commits via git rebase --interactive?

git

Solution

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.

Problem

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 buried in history? i.e. I ran `git reset HEAD^` and did my modifications. Now I want rebase to continue, which requires me to commit my changes. I'd like to modify my old commit message, but the problem is, if I run `git commit --amend`, I'm given the commit message of the commit before the one I'm actually modifiying -- and I certainly don't want to merge my changes into that commit. So how do I retrieve my old commit message for the commit I'm working on now?

Original source

Related problems