Question

On a reasonably large project I occasionally find myself in the following situation during a merge (I'm using the Windows GUI for Git called GitExtensions, but I'm equally comfortable with the command line):

File does not have a local revision. The file has been deleted locally (ours) but modified remotely (theirs).

I then get options to either: "Delete file (ours)", "Keep modified (theirs)", or "Keep base file".

I understand what has happened here and what these options are, but in most cases I don't know how to proceed unless I can see the changes that were made to the file on the branch that I'm merging in. If it was an unimportant change (whitespace / formatting / 'using' statements) then it doesn't matter and I can just keep the deletion, but if they made some more significant changes then I'm going to have to spend some time manually hunting these down and merging them.

Does anyone know of a git command I can run that will show me a diff of base -> remote in this situation? At the moment when this happens I'm going over to my colleague's desk to ask them what changes they made to that file so I can continue with my merge.

Was it helpful?

Solution

Well, it's not the best solution, but it's possibly the easiest. If you start the merge in Git (but before you act on it) Git will create a .BASE, .LOCAL and .REMOTE file in the same location as the file you need to merge.

In the case I've outlined above either .LOCAL or .REMOTE will be missing (depending on who deleted the file), but you can still go to the folder in question and manually diff either .BASE -> .REMOTE or .BASE -> .LOCAL.

This is probably easiest for Windows users.

If you really want to use the command line you can run

git merge-base <mergingBranch> HEAD

to find out the base commit hash. Then, using part of bundacia's answer above:

git difftool <mergeBase>..MERGE_HEAD -- foo.file

OTHER TIPS

You can git a list of the changes made to the file on the remote with this command:

git log -p MERGE_HEAD -- foo

Explanation:

foo is the file in question.

MERGE_HEAD points to the HEAD of the remote branch you're merging with

-p causes log to print the diffs with each commit

I was successful using Git Gui. It came as part of msysgit and can be accessed from the Windows Explorer context menu.

At the point where git merge tells me to fix the conflicts and then commit, I opened Git Gui (see screenshot below).

In the upper-left corner, it shows all changes that are unstaged (because of conflicts). To the right of it, there's a diff of the file in question. It tells me that the local version has been deleted (first two lines), but also shows the remote changes (3rd-last line). I'm pretty happy with that!

Git Gui

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top