How do I resolve a conflict after git pull?

GitConflictGit MergeGit Pull

Git Problem Overview


I have to solve some conflict after a git pull.

$ git pull
CONFLICT (rename/add): Renamed vignette_generator_mashed.h->vision_problem_8.h in 49423dd0d47abe6d839a783b5517bdfd200a202f. vision_problem_8.h added in HEAD
Added as vision_problem_8.h~HEAD_1 instead
Removed vignette_generator_cross_square.cc
Automatic merge failed; fix conflicts and then commit the result.

So I googled it a bit, and found people saying using git mergetool. But here is what I got:

$ git mergetool
merge tool candidates: meld kdiff3 tkdiff xxdiff meld gvimdiff emerge opendiff emerge vimdiff
No files need merging
$ git mergetool opendiff
merge tool candidates: meld kdiff3 tkdiff xxdiff meld gvimdiff emerge opendiff emerge vimdiff
opendiff: file not found

So does it mean I have to install something?

What if I simply want the version from git pull to overwrite everything?

Git Solutions


Solution 1 - Git

You don't need mergetool for this. It can be resolved pretty easily manually.

Your conflict is that your local commits added a file, vision_problem_8.h, that a remote commit also created, by a rename from vignette_generator_mashed.h. If you run ls -l vision_problem_8.h* you will probably see multiple versions of this file that git has preserved for you. One of them will be yours, another of them will be the remote version. You can use an editor or whatever tools you like to resolve the conflicting contents. When you're done, git add the affected files and commit to complete the merge.

If you just want to use the remote commit's version, then you can just move the copy that you didn't write into place and git add it.


Regarding the merge tools, have a look at git help mergetool. Basically, it's going to try running each of the included possibilities until it finds one, or use one you have explicitly configured.

Solution 2 - Git

I think you just forgot "-t" switch at your command line. According git help page it stands for "-t , --tool=" so it makes what you intended to.

Try:

git mergetool -t gvimdiff

Of course you may use your prefered merge tool instead of mine gvimdiff, meld is great too...

Solution 3 - Git

If you run your merge from a subdirectory of your project, git will run the merge for your whole project. However, mergetool can only see (and merge) files in or below the working directory. So, if this scenario occurs, make sure you are trying to run your conflict resolution from the top-level directory in your project.

Solution 4 - Git

What if I simply want the version from git pull to overwrite everything? If you want just that you should use:

 git fetch
 git reset --hard origin/your-branch-name

Solution 5 - Git

If you have a proper branching strategy - aka features are merged into develop , just before merge rebased etc. , most often when you want to run a git pull on a branch you basically want to get all the new stuff from the git server, and late on apply your own stuff , which is git lingua franca is something like this:

# put all my changes on the stash 
git stash 

# fully reset the current branch to the state it is on the server
git clean -d -x -f ; git reset HEAD --hard ; git pull --force

# apply your own changes 
git stash pop

You could also instead of stash put you current state into a tmp branch ... but eventually if there are conflicts you would have to manually resolve them ...

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTimView Question on Stackoverflow
Solution 1 - GitPhil MillerView Answer on Stackoverflow
Solution 2 - Gitmano2a0c40View Answer on Stackoverflow
Solution 3 - GitBluejackView Answer on Stackoverflow
Solution 4 - GitsaferJoView Answer on Stackoverflow
Solution 5 - GitYordan GeorgievView Answer on Stackoverflow