#yyds干货盘点#git commit --amend 命令
  Qp5JTyIxtbwu 2023年12月06日 12 0
git commit --amend

有时候可能Git提交后发现还有文件需要修改,当这个提交没有被推送到远程时,可以用此命令覆盖提交,避免commit记录混乱。

常用参数:

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

示例

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

文档描述

--amend
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].)

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年12月06日 0

暂无评论

推荐阅读
  DF5J4hb0hcmT   2023年12月12日   13   0   0 服务器git
  lh6O4DgR0ZQ8   2023年11月22日   16   0   0 Memory字段sed
Qp5JTyIxtbwu