Reputation: 1933
I have two Git branches, mybranch
(which is checked out) and theirbranch
. I would like to merge theirbranch
into mybranch
, resolving conflicts by keeping my version of a file if I've changed it (i.e. it has changed on mybranch
since the last common ancestor) and their version of the file if I haven't.
How can I do this in Git?
Two things that don't work:
git merge -s ours
: this keeps my copy of all files, even if I haven't changed them.git merge -Xours
: this keeps non-conflicting hunks from theirbranch
in files that I've changed; I want to ignore all hunks from theirbranch
in files I've changed.Upvotes: 1
Views: 55
Reputation: 1933
Here is one solution (assumes use of a Bash-like shell):
git merge theirbranch
git diff --name-only "$(git merge-base theirbranch HEAD)"..HEAD \
| xargs git checkout HEAD
git commit
It would be great if someone could suggest something shorter!
Upvotes: 1