使用我的所有更改来解决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.