Git merge: accept theirs for multiple conflicts
52,475
This will do it if you're mid-merge:
git merge test-development
# Automatic merge failed, a bunch of conflicts!
git checkout --theirs ./path
git add ./path
git commit
Author by
SecondGear
Updated on July 05, 2022Comments
-
SecondGear almost 2 years
I'm trying to merge a git branch (test-development) back into master. There are lots of merge conflicts but I want as many as possible to be resolved via --theirs. Is there a way to tell git to merge with --theirs in bulk?
-
SecondGear about 10 yearsThanks, I've tried a bunch of variations to no avail.
[sekingerg@centos-sekinger master2]$ git status # On branch master nothing to commit (working directory clean) [sekingerg@centos-sekinger master2]$ git branch * master [sekingerg@centos-sekinger master2]$ git checkout --theirs . [sekingerg@centos-sekinger master2]$ git add . [sekingerg@centos-sekinger master2]$ git commit # On branch master nothing to commit (working directory clean) [sekingerg@centos-sekinger master2]$
-
Ralf Marmorglatt about 10 yearsWell, you need to actually do the merge -- I edited the merge command into my answer.
-
Ralf Marmorglatt about 10 yearsAlso: this will bring all of the changes from
test-development
that don't conflict intomaster
, and accepttest-development
's version overmaster
's for any that conflict. Is that what you want, or do you want everything to look liketest-development
unconditionally, whever it conflicts or not? -
SecondGear about 10 yearsThis really helped. As it turned out, it was only half my problem. I use VitrualBox on a windows machine and have my git repo on a shared drive which means it's really on a NTFS partition. We've had a number of file renames where only case was changed in the filenames. Doing this over the shared folder proved to be extremely problematic. I cloned the master onto a ext4 partition and all of the odd errors I was seeing are gone.
-
Rene Wooller over 8 yearsWARNING: this will silently overwrite any changes in your local workspace, even in files that are not conflicted.
-
Spenhouet almost 4 yearsAdditional tip: You can do this for multiple files like this:
git checkout --theirs ./*
andgit add ./*
-
Adam Hughes about 3 yearsAnyway to update the answer w/ what to do if you're not mid merge? Ie from scratch? Just to make this a great reference...
-
PostCodeism almost 3 years@Spenhouet legend!
-
alper almost 3 years@Spenhouet
grep -lr '<<<<<<<' . | xargs git checkout --theirs && git add --all
seems like a better option