Git分支的目录比较

Nat*_*ons 14 git beyondcompare beyondcompare3

我最喜欢的svn工作流程之一是使用Beyond Compare的文件夹比较功能来查看两个分支或分支和主干之间的净差异.有没有办法在git中执行此操作而无需手动创建同一存储库的多个克隆?

当我问这个问题时,我发现我可以写一个脚本,将当前的repo克隆到一个临时目录,检出所需的分支,然后用两个目录作为参数调用BCompare.exe.使用调用文件夹比较视图

BCompare.exe path/to/folder1 path/to/folder2
Run Code Online (Sandbox Code Playgroud)

这听起来合理吗?在完成Beyond Compare之后,我能否删除额外的克隆?

Von*_*onC 30

这个(比较目录而不是逐个文件)应该很快就可以使用:
参见[ANNOUNCE] Git 1.7.11.rc1:

" git difftool"学会了" --dir-diff"选项来生成外部差异工具,这些工具可以在填充两个临时目录后一次比较两个目录层次结构,而不是每个文件对运行一次外部工具实例.

从这个git的分支看到" 补丁difftool:教difftool来处理目录差异 " :

difftool调用' '来比较修改多个文件的一系列提交时,它会为每个更改的文件打开一个单独的diff工具实例.

新的' --dir-diff'选项将所有修改后的文件复制到临时位置,并在diff工具的单个实例中对它们运行目录diff.

  • 天哪,这改变了我的生活! (2认同)

Rus*_*lva 2

听起来您已经找到了正确的答案 - 使用git clonegit checkout设置一个目录进行比较,然后运行BCompare.exe​​. 下面的脚本可能是一个很好的起点。

#!/bin/sh
(                              # execute in a subshell so you can continue
                               #   working in the current shell
    set -o xtrace              # bash setting that echos each command before it's executed
    > /tmp/auto_bcompare_log   # truncate existing log file
    BRANCH="$1"                # get branch argument from command line
    TEMPDIR=`mktemp -d`        # get a temp directory
    CWD=`pwd`                  # remember the current directory
    git clone $CWD $TEMPDIR
    cd $TEMPDIR
    git checkout $BRANCH
    cd $CWD
    BCompare.exe $CWD $TEMPDIR
    rm -rf $TEMPDIR
) >> /tmp/auto_bcompare_log 2>&1 < /dev/null & # background and redirect
                                               # stdout/stderr/stdin
Run Code Online (Sandbox Code Playgroud)