gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 13:21:24 25 4
gpt4 key购买 nike

我将 Git for Windows 与 xltrail extension 一起使用在使用 git diff <Excel workbook> 时提供可读的输出.我也在使用图形差异/merge 工具 Beyond Compare 4 Pro在使用 git difftool 时运行并提供了一个很好的并排差异和三向 merge 界面。

但是,当我运行 git difftool <Excel workbook> , 我得到正常的 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

最佳答案

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

创建可执行脚本xltrail-bc-diff.sh在现有C:\Users\<User>\AppData\Local\Programs\Git xltrail\目录:

#!/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 差异和 merge 工具相关联。更改差异条目以使用 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 workbook>应该在 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

然后,您需要将文件扩展名与此差异链接,更新您的 .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 的差异输出,但这是唯一剩下要做的事情。

关于excel - 如何在 Beyond Compare 中查看 Excel 工作簿的 xltrail 生成差异?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52995590/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com