git commit 修改提交说明信息

修改最近的提交

  • 未push的提交
git commit -amend -m "new commit message"

也可以在修改前添加更多的信息

git add .
git commit -amend -m "new commit message"
  • 已经push的提交
git commit -amend -m "new commit message"
git push --force branch-name

修改更旧的提交

git rebase -i HEAD~5

接着会显示最近的几次提交

pick 43f8707f9 fix: update dependency json5 to ^2.1.1
pick cea1fb88a fix: update dependency verdaccio to ^4.3.3
pick aa540c364 fix: update dependency webpack-dev-server to ^3.8.2
pick c5e078656 chore: update dependency flow-bin to ^0.109.0
pick 11ce0ab34 fix: Fix spelling.

越往下,提交越新,使用上下键移动光标,并将需要重新编辑的提交前的pick 转为 reword, 保存,退出编辑器。
然后会依次打开修改信息的窗口,编辑保存即可。

git push --force branch-name

参考

https://linuxize.com/post/change-git-commit-message/

如有不当,欢迎指正 :)
原文地址:https://www.cnblogs.com/lif323/p/14727588.html