0

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

mysticalstick
  • 155
  • 6
  • 21
  • 1
    What's the point of keeping the files tracked then? – choroba Jul 13 '16 at 19:05
  • you have a point. My project is over a thousand files so when I initialized I just did `git add .` without realizing that it might cause merge conflicts not worth keeping track of. I will remove them from the repository thanks. But in the case they were useful is there any way I can go a merge of specific files only? – mysticalstick Jul 13 '16 at 19:07
  • Also: consider adding those files - or a pattern matching them - to your .gitignore. This will keep them from being tracked at all; better in the long run if they aren't necessary. – Conduit Jul 13 '16 at 19:26
  • Yes I just discovered this functionality and I've created the file. Thanks for your help! – mysticalstick Jul 13 '16 at 19:55

2 Answers2

2

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
Conduit
  • 2,675
  • 1
  • 26
  • 39
0

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.

choroba
  • 231,213
  • 25
  • 204
  • 289