dou*_*oug 36 git macos command-line filemerge
我是OS X上的新手,我正在通过命令行使用它.我来自Tortoise SVN和Beyond Compare on Windows的世界.
我希望能够将差异发送到FileMerge.
我只需使用以下命令即可使用TextMate执行此操作:
git diff | mate
Run Code Online (Sandbox Code Playgroud)
但我不知道如何设置,所以我可以使用FileMerge?
und*_*ees 52
虽然它与将stdin管道输入到脚本中的方式不完全相同,但您可以这样做:
git difftool -t opendiff -y
Run Code Online (Sandbox Code Playgroud)
这将为每个文件启动FileMerge一次.一次完成整个项目树需要一些脚本.
另见这个问题.
Syz*_*ies 14
创建可执行脚本 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"
Run Code Online (Sandbox Code Playgroud)
现在编辑您的.gitconfig文件以包含行
[diff]
external = <path-to>/git-diff-cmd.sh
Run Code Online (Sandbox Code Playgroud)
......取而代之<path-to>的是git-diff-cmd.sh.现在git diff将使用FileMerge,并正确显示UTF-8 Unicode字符.
这是一个脚本(最初由Toby White提供),我讨厌比较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
# - 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
Run Code Online (Sandbox Code Playgroud)
把它放在你的路上.我更喜欢~/bin/git-opendiff,这意味着git opendiff ...按预期工作.
更新:在没有参数的情况下调用diff非暂停更改,添加-h(帮助)选项.
更新:diff子目录-- <path>.也是更好的参数解析.
| 归档时间: |
|
| 查看次数: |
19055 次 |
| 最近记录: |