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.
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.
Note that, starting git1.7.9.6 (and git1.7.10+),
git merge
itself will always trigger the editor, for you to add details to a merge.It also introduces an environment variable
GIT_MERGE_AUTOEDIT
to help older scripts decline this behavior.See "Anticipating Git 1.7.10":
Linus said:
Note that, before Git 2.17 (Q2 2018), "
git rebase -p
" mangled log messages of a merge commit, which is now fixed.See commit ed5144d (08 Feb 2018) by Gregory Herrero (``).
Suggested-by: Vegard Nossum (
vegard
), and Quentin Casasnovas (casasnovas
).(Merged by Junio C Hamano --
gitster
-- in commit 8b49408, 27 Feb 2018)git merge --edit
Allows you to give the comment even in case of non-interactive merge.
git merge --edit --no-ff
can be useful if you follow git flow with rebasing on development branch and merging into it with no fast forward.If you add the
--preserve-merges
option (or its synonym,-p
) to thegit 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:Another nice answer using only primitive commands -- by knittl https://stackoverflow.com/a/7599522/94687:
or a better (more correct) final rebase command:
BTW, using the primitive commands might have the nice "feature" of not consuming too much CPU and making you wait unknown time until Git finishes thinking about the list of commits needing to be rebased in the case of
git rebase -p -i HEAD^^^^
(such a command which would result in a list of only 4 last commits with the merge as last one in my case in my case took around 50 secs!).The
git rebase -i HEAD~5
command pops up the editor. It lists the specified commits (in this case five of them). The first column containspick
for every commit. Just replacepick
withreword
in that editor and save+close the editor. Then git will pop up the editor for every commit where you changedpick
toreword
and will let you edit the commit message.