如何在FileMerge中使用git在OS X上作为diff工具?

我是新来的OS X上,我通过命令行使用它。 我来自Windows上的Tortoise SVN和Beyond Compare的世界。

我想能够发送差异FileMerge。

我能够用TextMate做到这一点,只需使用:

git diff | mate 

但我不知道如何设置,所以我可以使用FileMerge呢?

虽然它不完全相同的pipe道标准input脚本,你可以这样做:

 git difftool -t opendiff -y 

这将为每个文件启动一次FileMerge。 一次做整个项目树需要一些脚本 。

另见这个问题 。

创build一个可执行脚本git-diff-cmd.sh

 #!/bin/bash xattr -w com.apple.TextEncoding "UTF-8;134217984" "$2" xattr -w com.apple.TextEncoding "UTF-8;134217984" "$5" /usr/bin/opendiff "$2" "$5" -merge "$1" 

现在编辑你的.gitconfig文件来包含这些行

 [diff] external = <path-to>/git-diff-cmd.sh 

…将<path-to>replace为git-diff-cmd.sh的path。 现在git diff将使用FileMerge,并正确显示UTF-8 Unicode字符。

这是一个脚本(最初由托比·怀特),我砍了比较FileMerge中的整个目录结构,而不是单独打开每个文件。

 #!/bin/sh # # This script was written by Toby White under an unknown license, and published # on the Git mailing list: # # http://kerneltrap.org/mailarchive/git/2007/11/21/435536 # # Superficial changes were made by Nathan de Vries to allow the script to be # run under Leopard. # # Adapted by Daniel Miller : http://stackoverflow.com/a/12957945/10840 # - allow changes to be saved back to the working copy when diffing against HEAD # - work when FileMerge is already open # - always compare archived copies so ignored files are excluded from the diff # - allow diff of unstaged changes (no arguments); creates a dangling commit # # Known issues: # - Always uses the same two directories (/tmp/git-opendiff-old and # /tmp/git-opendiff-new); THEY WILL BE DELETED IF THEY ALREADY EXIST. # Ugly, I know, but it makes the script work even if FileMerge is open. # - Does not show unstaged changes. if test "$1" = -h; then echo "usage: $0 [--cached | <ref>] [<ref>]" exit elif test $# = 0; then # diff unstaged changes # http://stackoverflow.com/a/12010656/10840 NEW=$(git stash create) OLD=HEAD elif test "$1" = --cached; then # diff staged changes OLD=HEAD NEW=`git write-tree` shift fi if test $# -gt 0; then OLD="$1"; shift fi test $# -gt 0 && test -z "$CACHED" && NEW="$1" TMP_OLD=/tmp/git-opendiff-old TMP_NEW=/tmp/git-opendiff-new test -d $TMP_OLD && rm -rf $TMP_OLD; mkdir $TMP_OLD test -d $TMP_NEW && rm -rf $TMP_NEW; mkdir $TMP_NEW TMP_OLD=$TMP_OLD/$OLD; mkdir -p $TMP_OLD git archive --format=tar $OLD | (cd $TMP_OLD; tar xf -) if test -z "$NEW"; then SAVE_TO=$(git rev-parse --show-cdup) test -z "$cdup" && SAVE_TO=. git archive --format=tar HEAD | (cd $TMP_NEW; tar xf -) opendiff $TMP_OLD $TMP_NEW -merge $SAVE_TO else TMP_NEW=$TMP_NEW/$NEW; mkdir -p $TMP_NEW git archive --format=tar $NEW | (cd $TMP_NEW; tar xf -) opendiff $TMP_OLD $TMP_NEW fi 

把这个放在你的路上。 我更喜欢~/bin/git-opendiff ,这意味着git opendiff ...按预期工作。

更新:比较未调用的变化时调用没有参数,添加-h (帮助)选项。