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

后端 未结 7 1913
有刺的猬
有刺的猬 2020-12-07 08:40

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 befo

7条回答
  •  广开言路
    2020-12-07 09:39

    Another nice answer using only primitive commands -- by knittl https://stackoverflow.com/a/7599522/94687:

    git checkout 
    git commit --amend # edit message
    git rebase HEAD previous_branch
    

    or a better (more correct) final rebase command:

    git rebase  previous_branch --onto HEAD
    

    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!).

提交回复
热议问题