2

So I have two branches, lets say Branch A and Branch B I have merged branch A into branch B.

git checkout B
git merge A

Now I want to resolve differences in favor of branch A in command line. How do I do it?

Vahagn Tumanyan
  • 500
  • 1
  • 13
  • 29
  • 3
    Possible duplicate of [Resolve Git merge conflicts in favor of their changes during a pull](http://stackoverflow.com/questions/10697463/resolve-git-merge-conflicts-in-favor-of-their-changes-during-a-pull) – ckruczek Apr 05 '17 at 09:53
  • You **have** merged (meaning you're done merging) or are you in the middle of that merge with conflicts? – Lasse V. Karlsen Apr 05 '17 at 10:16
  • I mean I have already merged it, and am in the conflicted state. – Vahagn Tumanyan Apr 05 '17 at 10:18
  • Those are contradictory claims: if you are in conflicted state, you are still in the act of merging. (In fact, you're still merging up until you run `git commit` to conclude the merge, even once you `git add` the resolved files.) – torek Apr 05 '17 at 11:14
  • Alright. What I mean is perhaps then I have run the git merge command, have conflicts, have not yet committed anything, and have to resolve conflicts (usually by hand) and commit. However now I just want to use the branch that has been merged and commit, I am at the state of resolving conflicts. – Vahagn Tumanyan Apr 05 '17 at 11:17

1 Answers1

7

You're looking for the the -s recursive -Xtheirs option for git merge.

This option does the opposite of the following:

...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...

Since you've already started the merge, you're going to want abort it since you cannot apply this merge strategy during a current merge.

git merge --abort

then re-do the merge as follows

git merge -s recursive -Xtheirs

That will do the merge so that all of the 'conflicts' are auto-picked to be from branch A

g19fanatic
  • 10,567
  • 6
  • 33
  • 63
  • 1
    While you cannot change the *strategy* (it's too late, the strategy has already run its course), you *can* actually merge each individual file with the equivalent of `-X theirs`. But if you have not done any work you want to save, your method (`git merge --abort` and restart with `-X theirs`) is the way to go since that automates what you would otherwise have to do quite tediously, one file at a time. – torek Apr 05 '17 at 18:23
  • 2
    And how to merge individual files in `-X theirs` style? I did some work on resolving manually and now want to resolve leftovers as theirs. – arrowd Mar 11 '18 at 10:42