使用我的所有更改来解决Git合并冲突,放弃他们的更改 [英] Resolve Git merge conflict using all my changes, discarding theirs

查看:1064
本文介绍了使用我的所有更改来解决Git合并冲突,放弃他们的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将分支A合并到分支B时,Git报告了几个冲突。我想通过保留每个文件的分支A的版本来解决冲突。我不关心分支B中的内容。

While merging branch A into branch B, Git reported several conflicts. I want to resolve the conflicts by keeping branch A's version of each file. I don't care about the content in branch B.

是否有一个命令可以用来解决所有合并冲突:保留我的文件版本在分支A)?

Is there a command I can use to resolve all the merge conflicts by keeping my version of the file (the version within branch A)?

推荐答案

事实上,使用Git的术语你想放弃我们的并保留他们的。这是因为当你进行合并时,你在分支B上,这使得我们的。

In fact, using Git's terminology you want to discard "ours" and keep "theirs". This is because you are on branch B when you do the merge, which makes that "ours".

git checkout B
git merge -s recursive -X theirs A

从文档:

From the documentation:

The recursive strategy can take the following options:

ours
    This option forces conflicting hunks to be auto-resolved
    cleanly by favoring our version. Changes from the other tree
    that do not conflict with our side are reflected to the merge
    result. For a binary file, the entire contents are taken from
    our side.

    This should not be confused with the ours merge strategy, which
    does not even look at what the other tree contains at all. It
    discards everything the other tree did, declaring our history
    contains all that happened in it.

theirs
    This is the opposite of ours.

这篇关于使用我的所有更改来解决Git合并冲突,放弃他们的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆