撤消上次提交/合并
我把我的 git 仓库弄乱了一点。我在一个单独的分支中开发了一个功能。完成工作后,我切换到master将其合并到其中,但我的伙伴推送了一些与我的冲突的文件。在合并、冲突和推动新的更改之后,我发现我也提交了合作伙伴的旧更改。
现在我想重做这个提交/合并。我试过 git reset --soft HEAD^
但是当我想推送时,我收到此错误消息再次推送之前合并远程更改
。
谁能帮助我吗?
I have messed up my git repo a little. I worked on a feature in a separate branch. After finishing the work, I switched to the master to merge it into, but my partner pushed a few files which came into conflict with mine. After the merge, the conflict and pushing the new changes, I saw that I committed the older changes of my partner too.
Now I want to redo this commit/merge. I triedgit reset --soft HEAD^
but when I wanted to push, I got this error message Merge the remote changes before pushing again
.
Can anyone help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你的功能分支仍然会指向你的工作。您不会丢失这些更改。
正如plaes所说,您可以将master重置回一个
如果您想从分支中获取一些特定文件而不合并,您可以检查它们:
如果您想要合并之前从master中获取一些文件,您也可以检查这些:
这并不理想,但有时这是需要的。合并/可能/意味着您拒绝合并中任何一方的一些更改。实现正确合并的最佳方法是:
从 master 开始,然后从上面运行 git checkout 命令,最后提交:
当您现在推送此分支时,您需要添加
force
选项或
Hope这有帮助。
Your feature branch will still point to your work. You will not lose those changes.
As plaes said, you can reset master back one with
If you want to grab some specific files from your branch without merging, you can check them out:
If you want some files from master from before the merge you can also check these out:
This is not ideal but it is what is needed sometimes. A merge /may/ mean that you reject some changes from either side in a merge. The best way to attain a proper merge is to:
from master, then run the git checkout commands from above and finally commit:
When you push this branch now, you will need to add the
force
optionor
Hope this helps.
呵呵,你差不多明白了:
Hehe, you almost figured it out:
这里的问题是您想要撤消已经推送到中央存储库的更改。如果你一开始就没有推送它们,那么 git reset --hard/--soft/--mixed HEAD^ 就可以解决问题。
因此,当您重置 HEAD 时,当您尝试推送到原点并更新不是 HEAD 祖先的远程引用时,git 会抱怨。动武:
The problem here is that you want to undo changes that you already have pushed to the central repository. If you hadn't pushed them in the first place, a git reset --hard/--soft/--mixed HEAD^ would have done the trick.
So when you have reseted your HEAD git complains when you try to push to the origin and update the remote ref which is not an ancestor to your HEAD. Use --force:
使用 git reset --hard origin/master 代替,这将进行硬重置并删除合并。取自链接 撤消尚未推送的 Git 合并
Use git reset --hard origin/master instead, this will do hard reset as well as delete the merge as well. Take from link Undo a Git merge that hasn't been pushed yet
让我为像我这样不太了解 git 的用户简化一下:D
如果你想取消合并提交并将其从远程 git 中删除。按照:
或者
现在您已在本地成功重置,是时候在远程更新/同步了
Let me simplify it for the users that don't understand git very well, like me :D
If you want to unmerge the commit and remove it from the remote git as well. Follow:
or
Now you have successfully reset on your local, it's time to update/sync this on remote