Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Diff Word docx files in Sourcetree on Windows 7

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
like image 1000
sclarke81 Avatar asked Sep 23 '15 08:09

sclarke81


People also ask

Can git diff Word documents?

With Word Diff you can use Git's native cryptographic diff functionality - which ensures the authenticity and integrity of a document - to quickly verify what's changed in a given iteration, or compare different versions of the document over time, all with a single click.

How can I read docx files?

How to open a DOCX file. You can open a DOCX file with Microsoft Word in Windows and macOS. Word is the best option for opening DOCX files because it fully supports the formatting of Word documents, which includes images, charts, tables, and text spacing and alignment. Word is also available for Android and iOS devices ...


1 Answers

I was looking for a solution to the same problem. Pandoc seems not to be working well with SourceTree, and I was wondering if there's a valid alternative. Then I remembered that WinMerge solved this years ago with an external tool, xdocdiff. The steps:

  • 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)
    

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
     *.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
    

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

like image 99
Tognolo Avatar answered Oct 13 '22 11:10

Tognolo