恢复 git merge -s ours
我想恢复合并,因为我没有使用 git merge -s recursive -X ours ,而是使用了 git merge -s ours 。
我已阅读这篇关于恢复合并的博客文章,但它没有似乎不适合我的情况。
因此,我有 master
分支,然后是 topic
分支。在某个时候,我将 master
合并到 topic
中,然后将 topic
合并到 master
中。当我将 master
合并到 branch
时,我在一个文件上发生了冲突,但我认为它没有做任何重要的事情,所以我想我说 git 来跳过它,并且使用我的版本。就在那时,我使用了 git merge -s ours ,而不是 git merge -s recursive -X ours ,今天我发现它忽略了我的队友所做的一切。
现在,我正在尝试恢复此合并:
git checkout master
git revert -m 2 c475f0ac
这确实将我的合并中忽略的更改(我的队友的更改)引入树中。问题是现在,我的更改不再存在于树中。我尝试过恢复恢复,但没有成功。
关于如何恢复这样的合并有什么建议吗?
I want to revert a merge because instead of using git merge -s recursive -X ours
, I've used git merge -s ours
.
I've read this blog post about reverting merges, but it doesn't seem to work for my case.
So, I have the master
branch, and then the topic
branch. At some point I merged master
into topic
, and then merged topic
into master
. When I merged master
into branch
, I had a conflict on a file, but I figured it didn't do anything important so I thought I say git to skip it, and use my version. That's when I used git merge -s ours
, instead of git merge -s recursive -X ours
, which I found out today that it ignored everything one of my team mates did.
Now, I'm trying to revert this merge:
git checkout master
git revert -m 2 c475f0ac
This is indeed bringing in the tree the changes ignored in my merge (my team mate's changes). The problem is that now, my changes are no more in the tree. I've tried reverting the revert, but no success.
Any suggestion on how to revert such a merge?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
revert 子命令创建一个新的提交来撤消指定的提交,这对于恢复合并提交来说通常很复杂。
您可以将树设置为任何特定提交的状态,搜索合并提交(是 c475f0ac 吗?),然后将树设置为该提交的状态父级(请注意命令末尾的点,这很重要):
如果要将状态设置为提交的不同父级,则应该使用
等等。
您会发现 gitk 命令在继续之前分析提交很有用(选择您想要的提交):将
状态设置为上一个提交后,您可以提交
然后推送
The revert subcommand makes a new commit to undo the specified commit, this usually is complicated for revert merge commits
You can set the tree to the state of any specific commit, search the merge commit (is c475f0ac ?) and then set the tree to the state parent of that commit (note the dot at the end of the command, it's important):
If you want to set the state to different parent of the commit, you should use
And so on.
You will find useful the gitk command to analyze the commits before proceed (to choose the commit that you want):
After setting the state to the previous commit, you can commit
And then push