Git conflict resolution: git mergetool not working

I need to resolve conflicts in git, but as a beginner, not sure which is the most efficient way.

This is my situation:

enter image description here

I am in master and I need to commit and push all my changes.

$ git pull:

Error: your local changes to 'foo.cpp' will be overwritten by merge. Aborting Please make your changes or write them down before you can merge.

There are several conflicting files. Of course, I searched on the Internet:

How to resolve merge conflicts in Git?

Unfortunately, none of the solutions work. I can use stash (accept diff and clear it) and do manual resolution, but want to use git mergetool or SourceTree.

Here is what I tried:

 $ git config merge.conflictstyle diff3 $ git mergetool merge tool candidates: tortoisemerge emerge vimdiff No files need merging $ git mergetool -t vimdiff No files need merging $ git mergetool -t vimdiff foo foo.cpp: file does not need merging $ git diff foo.cpp diff --git a/foo.cpp b/foo.cpp index xxxxxx yyyyy --- a/foo.cpp +++ b/foo.cpp @@ ..... ..... <omitted> $ 

I'm not sure what happened. git mergetool is not working properly. It says that there is no need to merge. However, this shows the differences and git pull reports a conflict.

Q1) How to use mergetool to interactively resolve conflicts or merge?

Q2) Can I use SourceTree to resolve conflicts? I tried, but it is also not intuitive.

Thanks!

+4
source share
2 answers

The error you see is:

 error: Your local changes to 'foo.cpp' would be overwritten by merge. Aborting. Please, commit your changes or stash them before you can merge. 

is that you have uncommitted changes (he talks about it at the very top of the SourceTree screen). Any merge attempt will fail if you have unspecified changes. You have three options:

  • All changes (Use: git reset --hard )
  • Discard all changes (Use: git stash )
  • Commit all changes (use: git add ...; git commit ... )

After you do this, you will be allowed to unite. If you choose option number 3 above, then conflicts may arise; there will be no conflicts for options No. 1 or No. 2. [Note: for option # 2 you will do git stash pop later, and then conflicts can occur.]

For your Q1: do git config merge.tool diff3 (or vimdiff, or something else). Merging can be misleading (usually a three-way merger, so the tool shows three versions and a combined version).

For your Q2: SourceTree does not include its own merge tool; you will need to rely on the other (I use p4merge and SourceTree). Using these configuration options:

 difftool.sourcetree.cmd=/Applications/p4merge.app/Contents/MacOS/p4merge "$LOCAL" "$REMOTE" difftool.sourcetree.path= mergetool.sourcetree.cmd=/Applications/p4merge.app/Contents/MacOS/p4merge "$BASE" "$LOCAL" "$REMOTE" "$MERGED" mergetool.sourcetree.trustexitcode=true 
+4
source

You receive a conflict message because you made changes to a file that was modified on a remote device that will be pulled in. Therefore, this message should either hide or commit your changes.

If you do any of these things, then pull, there may or may not be conflicts. If the changes that you pulled out are not in the same places as your modifications, there will be no conflict, for example. If there is a mergetool, it should work to take care of it.

+1
source

All Articles