How to modify a specified commit?

后端 未结 16 1176
清酒与你
清酒与你 2020-11-22 01:53

I usually submit a list of commits for review. If I have the following commits:

  1. HEAD
  2. Commit3
  3. Commit2
16条回答
  •  粉色の甜心
    2020-11-22 02:53

    Based on Documentation

    Amending the message of older or multiple commit messages

    git rebase -i HEAD~3 
    

    The above displays a list of the last 3 commits on the current branch, change 3 to something else if you want more. The list will look similar to the following:

    pick e499d89 Delete CNAME
    pick 0c39034 Better README
    pick f7fde4a Change the commit message but push the same commit.
    

    Replace pick with reword before each commit message you want to change. Let say you change the second commit in the list, your file will look like the following:

    pick e499d89 Delete CNAME
    reword 0c39034 Better README
    pick f7fde4a Change the commit message but push the same commit.
    

    Save and close the commit list file, this will pop up a new editer for you to change your commit message, change the commit message and save.

    Finaly Force-push the amended commits.

    git push --force
    

提交回复
热议问题