Daily Archives: March 14, 2013

Git Merge and Diff

When it comes to comparing and merging changes with git repositories, I typically use EGit’s tools or just plain vim with “git diff” and “git merge” from a command line.  But for some projects, I work outside Eclipse yet still want a graphical view.  Such was the case today when working with a large set of changed files under Windows.

To set up WinMerge as a custom difftool and mergetool, I pieced together several recommendations and created the following.


                tool = winmerge
        [difftool "winmerge"]
                cmd = c:/usr/bin/git-difftool.bat \"$LOCAL\" \"$REMOTE\"
                prompt = false
                tool = winmerge
        [mergetool "winmerge"]
                cmd = c:/usr/bin/git-difftool.bat \"$LOCAL\" \"$REMOTE\"


	@echo off
	for /f "delims=" %%a in ('cygpath -w %1') do @set file1=%%a 
	for /f "delims=" %%a in ('cygpath -w %2') do @set file2=%%a 
	"WinMergeU.exe" -e -ub "%FILE1%" "%FILE2%"

Works like a charm.  I can use just “git diff” and “git merge” (with vim) for quick work, and use “git difftool” or “git mergetool” when I want a GUI for more involved comparing/merging.


Like O’Reilly cover art, today’s xkcd comic at top right is only loosely related to this content.  But it’s awesome, so follow the link.