Friday, February 5, 2010

Setting up visual diff and merge for Git on OSX

They are mentions around the web about the best visual diff and merge tools to use for Git on OSX - for example this question on StackOverflow.

However I decided to go with the suggestion inside of Pro Git. The following is a summary of what I did, extracted more or less from the book.

#!/bin/sh

# This script is a summary of the advice provided by the book Pro Git (Thanks to author).
# to create visual merge and diff scripts to be used from cmd line git
# Script by Peter Lynch (http://blog.peterlynch.ca)

# 1. Download p4merge from perforce
# http://www.perforce.com/perforce/downloads/macintoshlist.html#macosx104u ( summary )
# Download the "P4V: Visual Client", mount the the DMG, copy p4merge to /Applications

# 2. Create wrapper scripts
sudo cat > /usr/local/bin/extMerge <<extMerge
#!/bin/sh
/Application/p4merge.app/Contents/MacOS/p4merge \$* 
extMerge
sudo cat > /usr/local/bin/extDiff <<extDiff
#!/bin/sh
[ \$# -eq 7 ] && /usr/local/bin/extMerge "\$2" "\$5" 
extDiff

# 3. Set owner and perms
sudo chown root /usr/local/bin/extMerge
sudo chown root /usr/local/bin/extDiff
sudo chmod ugo+x /usr/local/bin/extMerge
sudo chmod ugo+x /usr/local/bin/extDiff

# 4. Configure Git to use our new scripts
git config --global merge.tool extMerge
git config --global mergetool.extMerge.cmd \
    'extMerge "$BASE" "$LOCAL" "$REMOTE" "$MERGED"'
git config --global mergetool.trustExitCode false
git config --global diff.external extDiff

# 5. confirm
git config -l
echo ----------
ls -la /usr/local/bin/ext*

Remember to execute the script using sudo or else you'll get permission denied errors.

Also, to bypass the external diff don't forget you can use
git diff --no-ext-diff
.

1 comment:

Post a Comment