Diff Word docx files in Sourcetree on Windows 7

2019-04-08 05:59发布

问题:

I have been trying to get a text diff of Word .docx files working in Sourcetree on Windows 7. I have followed the instructions here Using Microsoft Word with git to use Pandoc and can get it working from the command line. Unfortunately I can't get that diff to appear in Sourcetree. Is there something else I need to do to get this to work?

Here's my .gitattributes file that I've put in the root of my project:

# Add diff of docx files.
*.docx diff=word

Here's my .git\config file:

[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

回答1:

I was looking for the same problem. Pandoc seems not working well with SourceTree, and I was wondering for a valid alternative. Then I remebered that WinMerge solved years ago with an external tool, xdocdiff. The steps:

  • (If you alredy haven't) 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 takes 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)
    

    go on only if this command works;

  • Add or edit the .gitattributes file in the root of the project:

    *.doc diff=xdoc2txt
    *.xls 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
    

This lines allows me to see the diff preview inside SourceTree.



回答2:

It works for me with both pandoc or xdoc2txt after having set SourceTree > Tools > Options > Git > Use System Git !!