更改其他用户的提交消息?

时间:2017-01-17 16:36:05

标签: git

我正在尝试压制另一个用户推送的一些提交。即使提交已在我的git日志本地压缩,当我尝试强制推送到主分支时,它不会更改远程仓库的提交历史记录。有什么想法吗?

感谢。

1 个答案:

答案 0 :(得分:0)

经过几个小时的搜索,我发现我在重新定位和提交过程中错误地从我的主分支中删除了我的HEAD(我当前的目录),所以当我运行时

git push --force origin master

git向我发送一条确认消息,但实际上没有应用我在我所在的分支中所做的更改,只是来自我的主分支的更改。可以通过运行

来检查是否具有分离的HEAD
git symbolic-ref HEAD

如果它抛出错误,则分离头部。或

git branch

显示我所在的分支。

对于其他Git新手,解决方案是使用

将我的更改从分离的HEAD合并到原始分支
git branch temp (this creates a branch that is the same as the current repository)
git checkout temp (this attaches HEAD to temp)
git checkout master (moves HEAD back to master)
git merge temp (merges temp with master)
git push --force origin master (overwrites old commits that I've pushed)

可在此处找到更多信息:How can I reconcile detached HEAD with master/origin?

感谢所有回复本网站内容的人。