恢复 git merge -s ours

发布于 2024-09-09 01:45:12 字数 755 浏览 7 评论 0原文

我想恢复合并,因为我没有使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乄_柒ぐ汐 2024-09-16 01:45:12

revert 子命令创建一个新的提交来撤消指定的提交,这对于恢复合并提交来说通常很复杂。

您可以将树设置为任何特定提交的状态,搜索合并提交(是 c475f0ac 吗?),然后将树设置为该提交的状态父级(请注意命令末尾的点,这很重要):

git checkout c475f0ac^ .

如果要将状态设置为提交的不同父级,则应该使用

git checkout c475f0ac^2 .

等等。
您会发现 gitk 命令在继续之前分析提交很有用(选择您想要的提交):将

gitk c475f0ac

状态设置为上一个提交后,您可以提交

git commit --message 'restored tree to state previous to merge commit c475f0ac'

然后推送

git push

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):

git checkout c475f0ac^ .

If you want to set the state to different parent of the commit, you should use

git checkout c475f0ac^2 .

And so on.
You will find useful the gitk command to analyze the commits before proceed (to choose the commit that you want):

gitk c475f0ac

After setting the state to the previous commit, you can commit

git commit --message 'restored tree to state previous to merge commit c475f0ac'

And then push

git push
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文