如何在Beyond Compare中查看xltrail生成的Excel工作簿差异?

5
我正在使用Git for Windows,并使用xltrail扩展程序,以便在使用git diff <Excel工作簿>时提供可读的输出。 我还使用图形化的diff / merge工具Beyond Compare 4 Pro,当使用git difftool时运行,并提供一个漂亮的并排差异和三向合并界面。
然而,当我运行git difftool <Excel工作簿>时,我会得到正常的git diff输出,而没有提示打开Beyond Compare。如何让Git、xltrail和Beyond Compare一起工作?

编辑 #1

以下是此问题的完整示例:
$ git config diff.tool; git config difftool.bc.path; git config difftool.prompt
bc
c:/Program Files/Beyond Compare 4/bcomp.exe
false


$ cat .git/config
[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
[diff "xltrail"]
        command = git-xltrail-diff.exe
[merge "xltrail"]
        name = xltrail merge driver for Excel workbooks
        driver = git-xltrail-merge.exe %P %O %A %B


$ cat ~/.gitconfig
# This is Git's per-user configuration file.

[user]
        name = Andrew Keeton
        email = AKeeton@example.com

[push]
        default = simple

[alias]
        co  = checkout
        ci  = commit
        cam = commit -am
        st  = status
        br  = branch

        # short log
        shlog = log --pretty=format:\"%C(yellow bold)%h%Creset %ad %C(cyan)|%Creset %s%C(magenta)%d%Creset %C(bold)[%an]%Creset\" --date=short --name-only
        hist  = log --pretty=format:\"%C(yellow bold)%h%Creset %ad %C(cyan)|%Creset %s%C(magenta)%d%Creset %C(bold)[%an]%Creset\" --date=short --graph

[diff]
        tool = bc

[difftool "bc"]
        path = c:/Program Files/Beyond Compare 4/bcomp.exe

[difftool]
        prompt = false


$ git st
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   workbook.xlsm
        modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")


$ git diff README.md
diff --git a/README.md b/README.md
index a052e20..3fd700d 100644
--- a/README.md
+++ b/README.md
@@ -40,6 +40,11 @@

 ## Tips

+* Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+* Curabitur a dui eu massa feugiat varius tempor eget tellus.
+* Nullam et fringilla eros.
+* Etiam euismod ipsum enim, non molestie nunc varius eu.
+
 * In Excel, press `CTRL+G` to open the *Go To* window.  This makes it easy to find the various tables and "anchors."

 ## xltrail


$ git difftool README.md
<See screenshot of README.md in Beyond Compare 4>


$ git diff workbook.xlsm
diff --xltrail a/workbook.xlsm b/workbook.xlsm
--- a/workbook.xlsm/VBA/Module/modWorksheet
+++ b/workbook.xlsm/VBA/Module/modWorksheet
@@ -14,6 +14,7 @@
     Dim dDouble1 As Double
     Dim dDouble2 As Double
     Dim dDouble3 As Double
+    Dim sString1 As String
     Dim dDouble4 As Double

     Dim iInteger1 As Integer



$ git difftool workbook.xlsm
diff --xltrail a/workbook.xlsm b/workbook.xlsm
--- a/workbook.xlsm/VBA/Module/modWorksheet
+++ b/workbook.xlsm/VBA/Module/modWorksheet
@@ -14,6 +14,7 @@
     Dim dDouble1 As Double
     Dim dDouble2 As Double
     Dim dDouble3 As Double
+    Dim sString1 As String
     Dim dDouble4 As Double

     Dim iInteger1 As Integer

在Beyond Compare 4中的README.md截图

Screenshot of README.md in Beyond Compare 4

2个回答

4

完整解决方案(由提问者添加)

在现有的 C:\Users\\AppData\Local\Programs\Git xltrail\ 目录中创建一个可执行脚本 xltrail-bc-diff.sh

#!/bin/bash
#
# xltrail-bc-diff.sh massages the output of git-xltrail-diff.exe and passes it
# into Beyond Compare in "Text Patch" mode.
#
# Input arguments from `git diff` are:
#    $1   $2       $3      $4       $5       $6      $7
#    path old-file old-hex old-mode new-file new-hex new-mode

path="$1"
tempDiffPath=`mktemp --suffix=".diff"`

# xltrail's diff output is color-coded with no option to remove it
# (see https://github.com/ZoomerAnalytics/git-xltrail/issues/30) so we use
# sed to strip the color codes.
git-xltrail-diff.exe $@ | sed 's/\x1b\[[0-9;]*m//g' > $tempDiffPath

BCompare.exe -fv="Text Patch" $tempDiffPath

在你的git配置文件中添加以下内容:

[diff "xltrail-bc"]
    command = xltrail-bc-diff.sh

在代码库中应该有一个 .gitattributes 文件,由xltrail创建用于将Excel文件与xltrail差异和合并工具关联。 将差异条目更改为使用 xltrail-bc

*.xla diff=xltrail-bc
*.xlam diff=xltrail-bc
*.xls diff=xltrail-bc
*.xlsb diff=xltrail-bc
*.xlsm diff=xltrail-bc
*.xlsx diff=xltrail-bc
*.xlt diff=xltrail-bc
*.xltm diff=xltrail-bc
*.xltx diff=xltrail-bc

现在您可以使用 git diff <Excel工作簿> 命令在Beyond Compare中打开文件。


原始回答

首先,您需要设置Git以类似以下方式:

git config --global diff.tool bc4
git config --global difftool.bc4.cmd "\"C:/Program Files (x86)/Beyond Compare 4/BCompare.exe\" \"\$LOCAL\" \"\$REMOTE\""
git config --global difftool.prompt false

接下来,您可以检查/编辑.git/config文件,并确保具有以下内容:

[diff]
tool = bc4

如果不够,请发布您的.git/config文件。

编辑,以满足进一步需求。 似乎无法像那样插入xtrail和Beyond Compare。 我成功地复制了您的问题。 我认为在.gitattributes文件中可能有些事情可以做,但没有成功。

因此...唯一可能的解决方案是创建自己的diff脚本,并将所有工具连接在一起。这很复杂。

在我的电脑上,我尝试使用GNU / Bash脚本(您可以在Windows上安装Git Bash来获取支持),但您可能需要创建一个.bat文件。

首先,您需要更新您的.git/config配置文件,以指定到您的新脚本文件的路径,例如:

[diff "myComplexDiff"]
    command = C:/Users/XXX/Documents/complexGitDiff.sh

接下来,您需要将文件扩展名与此diff链接起来,通过更新您的.gitattributes文件,例如(要适应任何所需的扩展名):

*.xls diff=myComplexDiff

然后,脚本可能看起来像这样:
#!/bin/bash -x
# Sample of information given by git
# b851185776b7826a6cc82d3aa6a8d53fa47e0c26 100644 simpleTest.xls 0000000000000000000000000000000000000000 100644
fileName="$1"
tmpFile="/tmp/"$( date +'%s')"$fileName.diff"
git-xltrail-diff.exe $@ >"$tmpFile"
c:\\Program\ Files\\Beyond\ Compare\ 4\\bcomp.exe "$fileName" "$tmpFile"

实际上,我没有找到Beyond Compare接受git-xltrail-diff.exe差异输出的必要选项,但这是唯一剩下的事情要做。


我已经类似地设置了 git difftool(但是启用提示),因此当我执行 git difftool README.md 时,我会得到 Viewing (1/1): 'README.md'\n Launch 'bc' [Y/n]?,然后它会使用适当的并排差异在 Beyond Compare 中打开。 - Andrew Keeton
就像你所看到的,你的配置文件中缺少了 prompt=false。也许是你的全局 git 配置和本地仓库配置混淆了?尝试重新添加它。可以使用 git config 命令来实现,否则你可以手动在配置文件中添加。 - Bsquare ℬℬ
我把 prompt 改成了 false,但我不认为这会有影响。请参见我原帖中的 编辑 #1 - Andrew Keeton
我用一个新的复杂解决方案编辑了我的答案 ;) 如果您需要进一步的帮助,请告诉我。 - Bsquare ℬℬ
感谢您的帮助。我使用我的完整解决方案劫持了您的答案顶部,以便其他需要帮助的人可以首先看到它。 - Andrew Keeton
显示剩余2条评论

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接