I recently found P4Merge (thank you Twitter and Git Immersion) and instantly dropped WinMerge as my standard diff/merge tool. I really like the way it visualises the differences and the 3-way merge is really nicely done. P4Merge is the merge tool for Perforce (which I have never used) and is both free and can be downloaded separately from the rest of Perforce.
The download can be found here. Choose Browse by component->Clients->Visual Merge Tool as you do not want to download the whole Perforce client package. In the installer for P4Merge you can choose which components you wish to install, you only need the Visual Merge Tool (P4Merge).
Install p4merge and then set it as your merge tool for git by running the following two config commands:
git config --global merge.tool p4merge git config --global mergetool.p4merge.cmd 'p4merge.exe \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"'
EDIT: As pointed out by barik in the comments, in newer versions of git this works as well and is slightly simpler:
git config --global merge.tool p4merge git config --global mergetool.p4merge.path "C:/Program Files/Perforce/p4merge.exe"
P4Merge can be used for doing diffs and merges. If using P4Merge for diffs then call:
If the file you want to compare is already staged then use the –cached switch after that command.
When Git tells you that there has been conflict, to resolve it type:
This will open P4Merge and show three different versions of the file; your local version, the version you are trying to merge in (probably the master branch) and the base version. The base version is the common ancestor of the local version and the remote version. Choose which version wins or edit the merge manually and then save and quit P4Merge. Finally commit the merge and then remove any .orig files that may be left over. It should be possible to have git remove the .orig file automatically by setting mergetool.keepBackup to false in git config but I have not succeeded in getting that to work for me yet.
An example of using P4Merge
And this is what a 3-way merge looks like. The local version on the left, the base version in the middle and the remote version (the master branch) on the right. In the merge window at the bottom all three versions are currently selected. To select the local version, for example, I would click the blue diamond icon and then save and quit.
- Git for Windows tip: setting an editor (danlimerick.wordpress.com)
- Git for Windows tip: Setting shell aliases with msysgit (danlimerick.wordpress.com)