Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 修改推送提交消息_Git_Push_Commit Message_Git Amend - Fatal编程技术网

Git 修改推送提交消息

Git 修改推送提交消息,git,push,commit-message,git-amend,Git,Push,Commit Message,Git Amend,我只是做了一个提交,然后意识到我需要更改提交消息 因此,在我的本地回购协议中,我做到了: git commit --amend -m "New commit message" 但当我试图推动这一点时,我收到了大量的错误消息说 Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Merge the remote changes (e.g. 'git

我只是做了一个提交,然后意识到我需要更改提交消息

因此,在我的本地回购协议中,我做到了:

git commit --amend -m "New commit message"
但当我试图推动这一点时,我收到了大量的错误消息说

Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') and try again
这是修改我的信息的错误方式吗?最后,我不得不重置所有回购协议,然后用新消息再次提交


因此,我的问题是,修改已推送内容的提交消息的正确方法是什么?

简短回答:没有正确的方法

git commit--amend所做的是用一个类似但经过修改的commit“替换”上一个commit。你还没有真正改变最初的提交。它仍然存在,但不再有任何东西引用它,除非有什么东西开始引用它,否则它最终将被垃圾收集

这在本地完成时是透明的。但是,当您推动提交时,实际上已经太晚了。您已经与其他人共享了提交,这些人可能已经拉取了提交并基于该提交进行了工作。不能用另一个提交替换该提交

假设您进行了一次提交a(在提交B之后):


您可以执行git-push--force,但它可能会中断您的存储库。Git哲学反对出于某种原因改变历史

B - A    <- master
B - A
  \ 
    A'  <- master
local                            remote
B - A   <-master                 B - A    <- origin/master
local                            remote
B - A                            B - A    <- origin/master
  \ 
    A'  <- master
local                            remote
B - A                            B - A - C   <- origin/master
  \ 
    A'  <- master
local                            remote
B - A                            B - A - C
  \                                \
    A'  <- master                    A'   <- origin/master