Git: How to edit/reword a merge commit's message?

ma11hew28 picture ma11hew28 · Sep 2, 2011 · Viewed 71k times · Source

How do I edit or reword a merge commit's message?

git commit --amend works if it's the last commit made (HEAD), but what if it comes before HEAD?

git rebase -i HEAD~5 doesn't list the merge commits.

Answer

Mark Longair picture Mark Longair · Sep 2, 2011

If you add the --preserve-merges option (or its synonym, -p) to the git rebase -i command then git will try to preserve the merges when rebasing, rather than linearizing the history, and you should be able to amend the merge commits as well:

git rebase -i -p HEAD~5