Kerrick Staley
Kerrick Staley

Reputation: 1933

How can I resolve git merge conflicts by keeping my version of files that I changed?

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:

Upvotes: 1

Views: 55

Answers (1)

Kerrick Staley
Kerrick Staley

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

Related Questions