git commit --amend



  • --no-edit:不编辑
  • --reset-author:重置提交用户为当前用户
  • --author=:修改Git 的 author和 email 信息。


  1. 想修改提交的消息描述
git commit -amend -m <message>
  1. 想重新提交文件
git add .                         # 将修改的文件添加到暂存区
git commit -amend -m <message>    # 重新提交并修改消息


Replace the tip of the current branch by creating a new commit. The recorded tree is prepared as usual (including the effect of the -i and -o options and explicit pathspec), and the message from the original commit is used as the starting point, instead of an empty message, when no other message is specified from the command line via options such as -m, -F, -c, etc. The new commit has the same parents and author as the current one (the --reset-author option can countermand this).
It is a rough equivalent for:
$ git reset --soft HEAD^
$ ... do something else to come up with the right tree ...
$ git commit -c ORIG_HEAD
but can be used to amend a merge commit.
You should understand the implications of rewriting history if you amend a commit that has already been published. (See the "RECOVERING FROM UPSTREAM REBASE" section in git-rebase[1].)

699 声望15 粉丝