Modify the information of the last commit after git commit

Modify the information of the last commit after git commit

Just committed but no push yet

  1. git commit --amend
  2. You will enter the vim editor, click i, modify the commit information, click esc, and enter ZZ to exit.
  3. git log can see recent commit information

Just pushed, modify the latest commit

  1. git commit --amend
  2. You will enter the vim editor, click i, modify the commit information, click esc, and enter ZZ to exit.
  3. You can see the recent commit information in git log. After pulling, push to the remote (but pushing again after each pull will cause the original changes to be overwritten. Later, the direct force push was successful: git push origin HEAD:master --force)

Modify the commit information of historical push

  1. git rebase -i HEAD~3
  2. Indicates that the third to last status of the current version is to be modified.
  3. After this command is issued, three lines will appear:
pick:*******

pick:*******

pick:*******
复制代码
  1. If you want to modify any one, change the pick in that line to edit, then save and exit (click esc and enter ZZ to exit)

  2. At this time, you can find through git log that the last commit of git has become the one you selected. Then use:

    git commit --amend to modify the commit.

  3. After the modification is completed, use git rebase --continue

  4. Then push the changes to the remote: git push origin HEAD:master --force


If you have any special questions, you can leave a message~ we can help you solve it if you see it

Guess you like

Origin blog.csdn.net/qq_41998504/article/details/129030528