tags:

views:

5530

answers:

3

When merging topic branch "B" in "A" using git merge, I get some conflicts. I know all the conflicts can be solved using the version in "B".

I am aware of git merge -s ours. But what I want is something like git merge -s their.

Why it does not exist? How can I achieve the same result after the conflicting merge with hot git commands? (git checkout every unmerged file from B)

thanks

UPDATE: however, this solution just discard anything from branch A (the merge commit point to B version of the tree). This is not what I am looking for :(

+10  A: 

I solved my problem using

git checkout -m old
git checkout -b new B
git merge -s ours old
elmarco
a branch "B" from "old" branch
elmarco
@elmarco, okay, didn't know about this new thing.
Yar
+11  A: 

Older versions of git allowed you to use the "theirs" merge strategy:


git pull --strategy=theirs remote_branch

But this has since been removed, as explained in this message by Junio Hamano (the Git maintainer). As noted in the link, instead you would do this:


git fetch origin
get reset --hard origin

Beware, though, that this is different than an actual merge. You're solution is probably the option you're really looking for.

Pat Notz
thanks, I am not totally satisfy by my answer though, it was missing the checkout of other files in old. it was odd, I add to checkout them... to commit --amend them then.
elmarco
+3  A: 

One other thing to look at is adding the strategy with -X. For example:

git checkout branchA
git merge -Xtheirs branchB

This works for me in version 1.7.1 of Git. The only conflicts I see are if I have deleted a file in branchB. The merge will complain about that as a conflict. Basically, what happens is that when you checkout branchA the file you deleted in branchB will still be there. To fix the conflict, just do:

git rm {DELETED-FILE-NAME}

and the commit from there.

(If you happen to remember to delete the files first, the merge with -Xtheirs should not complain about conflicts)

anotherAlan