mysticalstick
mysticalstick

Reputation: 165

resolve merge conflicts without manually editing each file

I'm new to Git and I'm trying to find a quicker way to resolve merge conflicts. Say I tried to merge a branch to master and I get merge conflicts for some of the files.

Changes to be committed:

    modified:   ...

Unmerged paths:
   (use "git add <file>..." to mark resolution)

    both modified:   ...

Git goes into each of the both modified files and adds conflict-resolution markers right? (<<<<<<< this stuff). Normally I would go into the files and manually change them but in this case they are all bin files and not too relevant to my program working. Is there a way I can just stage all the modified files and specify that I want all the unmodified files to remain the way they were in the master before the merge. (basically disregard the changes from the branch to those files). Thanks

Upvotes: 0

Views: 1952

Answers (2)

Conduit
Conduit

Reputation: 2735

You must find the copy of the file you wish to use, check it out, stage changes, and then commit. For example:

git log 

(find out we want the file from commit ac3422d4ceba793ff9fd3df81159d23111a760e2)

git checkout ac3422d4ceba793ff9fd3df81159d23111a760e2 file/to/fix.txt
git add file/to/fix.txt
git commit -m "success!!"

What this does is:

  • replace the file with the one from the specified commit
  • stage the change and mark the merge conflict on the file as resolved
  • commit the change/merge

Upvotes: 3

choroba
choroba

Reputation: 241748

When merging, you can specify a "strategy". From git help merge:

ours

This resolves any number of heads, but the resulting tree of the merge is always that of the current branch head, effectively ignoring all changes from all other branches. It is meant to be used to supersede old development history of side branches. Note that this is different from the -Xours option to the recursive merge strategy.

Upvotes: 0

Related Questions