简体   繁体   English

无法更改(不是最后一个)推送的提交消息

[英]can not change the (not the last) pushed commit message

I wan't to change a commit message which is been pushed and its not the last commit. 我不会更改已推送的提交消息,而不是最后一次提交。 As git documents suggested i just done the rebase as follow: 正如git文档所建议的那样,我只是按如下方式进行了变基:

rebase -i HEAD~2

then edited the result as follows: 然后按如下方式编辑结果:

reword e499d89 some thig been done
pick 0c39034 some other thing been done

then saved the commit list file successfuly and after that edit of the reworded commit would prompted as follow: 然后成功保存提交列表文件,并且在对改写后的提交进行编辑后,将提示如下:

some thig been done
#some comments here
-->list of changelist here

i edited the commit message and save it, but after all idea git log shows no change in git commits and their messages. 我编辑了提交消息并保存了它,但是毕竟git日志在git提交及其消息中没有显示任何更改。

Finally the problem was because of commit message text, due to integration of issue tracker and git server we add issue id after a sharp sign in start of any commit so the commit would look like this: 最终 ,问题是由于提交消息文本,由于问题跟踪器和git服务器的集成,我们在任何提交开始的尖锐符号后添加了问题ID,因此提交看起来像这样:

#123 some thing been done

then in final phase of editing the commit message, the entire commit message was interpreted as another comment line (i suppose): 然后在编辑提交消息的最后阶段,整个提交消息被解释为另一个注释行(我想):

    #123 some thig been done
    #some comments here
    -->list of changelist here

So, just adding a space before sharp sign solved the problem and new commit been created: 因此,只需在尖号之前添加一个空格即可解决问题并创建新的提交:

 #123 some thig been done
#some comments here
-->list of changelist here

PS: I don't know if it could be called a bug of git or not?! PS:我不知道它是否可以称为git的bug?

After passing all operations: rewording -> typing the new commit message -> saving the file -> closing the file 通过所有操作后: 重新措词 ->输入新的提交消息->保存文件->关闭文件
You should force-push the amended commit to change the commit history: 您应该强制推送修改后的提交以更改提交历史记录:

$ git push --force

Suppose the commit log is ABCDE<-master and you want to modify C's commit message. 假设提交日志为ABCDE<-master并且您想修改C的提交消息。

git checkout master
git reset C --hard
git commit --amend
#modify the change commit message, save and quit
git cherry-pick C..E
#or git cherry-pick D E
#or git cherry-pick D;git cherry-pick E
git push origin -f master:master

If others have cloned or fetched your previous master , you need to notify them to update master to the latest version. 如果其他人已克隆或获取了您以前的master ,则需要通知他们以将master更新到最新版本。

Suppose they have local master as ABCDEFG . 假设他们具有本地master ABCDEFG

git fetch origin master
git reset B --hard
git rebase FETCH_HEAD
git cherry-pick F G

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM