2

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.

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

hawkharris
  • 2,570
  • 6
  • 25
  • 36

1 Answers1

4

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.
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • I'm wondering why the docs refer to it is a 'hunk' is this just a typo in the original docs where they wanted to write 'chunk'? – Philip Kirkbride Feb 14 '17 at 19:08
  • 1
    @PhilipKirkbride, I could only speculate about why that term was chosen. But it's not a typo: [hunks are referenced throughout Git's source code](https://github.com/git/git/search?utf8=%E2%9C%93&q=hunk) and [documentation](https://git-scm.com/docs/git-add). – ChrisGPT was on strike Feb 14 '17 at 19:30