-
-
Save k4gdw/5e5b71600cc0552a5e79aa5f2ca4d7d9 to your computer and use it in GitHub Desktop.
How to make git diff work perfectly with .docx files in Mac OS X (it even colors by word)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Execute the following commands one at a time from a bash prompt. | |
# download docx2txt by Sandeep Kumar | |
wget -O docx2txt.pl http://www.cs.indiana.edu/~kinzler/home/binp/docx2txt | |
# make a wrapper | |
echo '#!/bin/bash | |
docx2txt.pl $1 -' > docx2txt | |
chmod +x docx2txt | |
# make sure docx2txt.pl and docx2txt are your current PATH. Here's a guide | |
# http://shapeshed.com/using_custom_shell_scripts_on_osx_or_linux/ | |
mv docx2txt docx2txt.pl ~/bin/ | |
# set .gitattributes (According to the site where I found the original version | |
# of this script, you can't set this globally. It has to be set on a per-project | |
# basis. | |
echo "*.docx diff=word" >> .gitattributes | |
# add the following to ~/.gitconfig | |
# [diff "word"] | |
# binary = true | |
# textconv = docx2txt | |
git config --global diff.word.binary true | |
git config --global diff.word.textconv docx2txt | |
# add a new alias | |
# [alias] | |
# wdiff = diff --color-words | |
git config --global alias.wdiff "diff --color-words" | |
# try it. Create a new folder and initialize it as a git repository. | |
cd /c | |
md WordDiffTest | |
cd WordDiffTest | |
git init | |
# Open Word and create my_file.docx, add some content, then add it to the repository. | |
git add my_file.docx | |
git commit -m "Initial commit" | |
# change something in my_file.docx | |
git wdiff my_file.docx | |
# awesome! |
Use git commit
instead of relying on an alias git ci
the may or may not exist on the user's workstation. Also, append the git attributes stuff to an existing .gitattributes
file or create it if it doesn't already exist.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fixed some of the commands so that they were executable. For example, I provided git config commands to add the
[diff "word"]
section to the~/.gitconfig
file.