在Windows 7的Sourcetree中比较Word文档中的差异

6
我一直在尝试在Windows 7上的Sourcetree中获取Word .docx文件的文本差异。我按照这里的说明(使用Microsoft Word与git)使用Pandoc,并可以从命令行中使其工作。不幸的是,我无法在Sourcetree中看到差异。我需要做些什么才能让它起作用呢?
这是我放在项目根目录下的.gitattributes文件:
# Add diff of docx files.
*.docx diff=word

这是我的 .git\config 文件:

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
    hideDotFiles = dotGitOnly
[diff "word"]
  textconv=pandoc --to=markdown
  prompt = false
[alias]
  wdiff = diff --word-diff=color --unified=1

您可能会对https://jira.atlassian.com/browse/SRCTREEWIN-1416感兴趣,但该工单尚未关闭。 - edi9999
谢谢提供链接。这意味着我无法让它工作。 - sclarke81
是的,这意味着在源代码树中未实现。 - edi9999
2个回答

6

我曾经遇到过同样的问题,发现Pandoc在与SourceTree配合时似乎效果不佳,因此想知道是否有其他有效的替代方案。后来我想起WinMerge多年前就使用了一个外部工具xdocdiff来解决这个问题。具体步骤如下:

  • If you haven't already, download xdocdiff here, you can install as suggested or put in a folder you like;

  • Add the folder in the Windows PATH variable, as described here (a reboot is required to take effect);

  • Verify that everything works by typing in a Command Line window the command xdoc2txt, the output will be the usage helper (like below):

     > xdoc2txt
     Usage: xdoc2txt [-s|-e|-j][-c][-f][-r=(0|1|2)] <filename...>
             -s : convert to ShiftJIS(default)
             -e : convert to EUC
             -j : convert to JIS
             -f : output to file
             -c : activate PDF cache
             -p : print property
             -n : ignore permission on PDF;(require cryptlib.dll)
             -r=(0|1|2) : ruby style(0:suppress 1:parentheses 2:aozora bunko
             -o=0 : other option; -o=0:no show PDF page#
             -g=# : PDF gap parameter
             -v : show version number
             -x : output existing cell only(for EXCEL2007)
    
只有当这个命令成功运行时才继续进行。
  • Add or edit the .gitattributes file in the root of the project:

     *.doc diff=xdoc2txt
     *.xls diff=xdoc2txt
     *.docx diff=xdoc2txt
     *.xlsx diff=xdoc2txt
     # ...
     # add any other supported extensions you need
    
  • Edit the .git\config file in the root of the project:

     [diff "xdoc2txt"]
       textconv = xdoc2txt
       cachetextconv = true
       binary = true
       prompt = false
    
这些代码行使我能够在SourceTree中看到差异预览。

我很高兴不是只有我一个人尝试过这个。然而,我已经尝试按照你的指示操作,但仍然无法使其工作。你使用的是哪个版本的SourceTree?我使用的是1.6.22.0版本。 - sclarke81
我的版本是1.6.20.0。确保在打开Windows命令行时,如果输入命令“xdoc2txt”,它不会返回“未找到命令”的错误。 - Tognolo
你是否成功执行了stage或discard hunk命令? 当前版本2.4.7.0可以显示差异,但是每当我尝试放弃一个hunk时,就会出现错误:'git apply'失败,代码为1:[...]。 错误:在搜索[...]时发生错误。 好吧,我猜从sourcetree返回到相应的hunks可能还有一些遗漏? - Tigerware
你如何使用Mercurial完成它? - skan

0

在设置 SourceTree > Tools > Options > Git > Use System Git 后,我使用 pandoc 或 xdoc2txt 都可以正常工作!


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