首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在OS上通过管道将FileMerge作为一个与git不同的工具?

如何在OS上通过管道将FileMerge作为一个与git不同的工具?
EN

Stack Overflow用户
提问于 2010-03-18 08:15:15
回答 4查看 19.7K关注 0票数 38

我是OS X上的git新手,我正在通过命令行使用它。我来自Windows上的乌龟SVN世界和Beyond Compare。

我希望能够将diffs发送到FileMerge。

我只需使用TextMate就可以做到这一点:

代码语言:javascript
复制
git diff | mate

但是我不确定如何设置,这样我才能使用FileMerge?

EN

回答 4

Stack Overflow用户

发布于 2010-03-18 09:18:59

尽管它与将stdin输送到脚本中并不完全相同,但您可以这样做:

代码语言:javascript
复制
git difftool -t opendiff -y

这将为每个文件启动一次FileMerge。一次完成整个项目树,takes a little scripting

另请参见this question

票数 54
EN

Stack Overflow用户

发布于 2011-08-31 09:58:34

创建可执行脚本git-diff-cmd.sh

代码语言:javascript
复制
#!/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文件,使其包含以下行

代码语言:javascript
复制
[diff]
    external = <path-to>/git-diff-cmd.sh

git-diff-cmd.sh的路径旁使用...replacing <path-to>。现在git diff将使用FileMerge,并正确显示UTF8UNICODE字符。

票数 15
EN

Stack Overflow用户

发布于 2012-10-18 23:14:50

下面是我用来比较FileMerge中的整个目录结构而不是单独打开每个文件的脚本(最初是Toby White编写的)。

代码语言:javascript
复制
#!/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 (帮助)选项。

更新:使用-- <path>的diff子目录。还有更好的参数解析。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2466821

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档