39

私は OS X で git を初めて使用し、コマンド ライン経由で使用しています。私は、Tortoise SVN と Windows 上の Beyond Compare の世界から来ました。

差分を FileMerge に送信できるようにしたいと考えています。

以下を使用するだけで、TextMate でこれを行うことができました。

git diff | mate

しかし、その設定方法がわからないので、代わりに FileMerge を使用できますか?

4

4 に答える 4

54

stdin をスクリプトにパイプするのとまったく同じではありませんが、次のようにすることができます。

git difftool -t opendiff -y

これにより、ファイルごとに 1 回 FileMerge が起動されます。プロジェクト ツリー全体を一度に実行するには、少しスクリプトを作成する必要があります

この質問も参照してください。

于 2010-03-18T01:18:59.250 に答える
15

実行可能スクリプトを作成する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>...へのパスで置き換えgit-diff-cmd.shます。FileMergegit diffを使用し、UTF-8Unicode文字を正しく表示します。

于 2011-08-31T01:58:33.873 に答える
5

これは、各ファイルを個別に開くのではなく、FileMerge でディレクトリ構造全体を比較するためにハックしたスクリプト (元は Toby White によるもの) です。

#!/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
# - allow diff of subdirectory within the repo
#
# 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.

OLD=
NEW=
FILEPATH=
HAS_ARGS=no
IGNORE_TO_PATH=no

# loosely based on https://stackoverflow.com/a/14787208/10840
while [ "$#" -ge 1 ]; do
    HAS_ARGS=yes
    case "$1" in
        -h)
            echo "usage: $0 [--cached | <ref> [<ref>]] [-- <path>]"
            exit 0
            ;;
        --cached)
            # diff staged changes
            NEW=$(git write-tree)
            OLD=HEAD
            IGNORE_TO_PATH=yes
            shift
            ;;
        --)
            shift
            FILEPATH="$@"
            break
            ;;
        *)
            if [[ "$IGNORE_TO_PATH" == "no" ]]; then
                if [ -z "$OLD" ]; then
                    OLD="$1"
                else
                    NEW="$1"
                    IGNORE_TO_PATH=yes
                fi
            fi
            shift
            ;;
    esac
done
if [ -z "$OLD" ]; then
    OLD=HEAD
fi
if [[ "$HAS_ARGS" == "no" ]]; then
    # diff unstaged changes
    # http://stackoverflow.com/a/12010656/10840
    NEW=$(git stash create)
    echo "diff unstaged changes"
fi

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 $FILEPATH | (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 $FILEPATH | (cd $TMP_NEW; tar xf -)
    opendiff $TMP_OLD/$FILEPATH $TMP_NEW/$FILEPATH -merge $SAVE_TO &> /dev/null &
else
    TMP_NEW=$TMP_NEW/$NEW; mkdir -p $TMP_NEW
    git archive --format=tar $NEW $FILEPATH | (cd $TMP_NEW; tar xf -)
    opendiff $TMP_OLD/$FILEPATH $TMP_NEW/$FILEPATH &> /dev/null &
fi

これをパスのどこかに置いてください。~/bin/git-opendiffつまり、期待どおりに動作しますgit opendiff ...

更新: 引数なしで呼び出されたときにステージングされていない変更を比較し、-h(help) オプションを追加しました。

更新: diff サブディレクトリと-- <path>. また、より良い引数の解析。

于 2012-10-18T15:14:50.183 に答える