Git-diffing Excel files, part 2
Posted on Tue 02 January 2018 in Tools
I previously wrote about how to get a useful diff for binary Excel files that reside in a Git repository.
This post adds some details that are big enough to deserve a separate post. They are:
- User-level configuration of Excel diffing.
- How to get an Excel diff from
git show
.
User-level configuration
In the previous post, I outlined how to add a diff driver to the
.git/config
file in a repository. To make the diff driver available to
all repositories for the current user, update the $HOME/.gitconfig
file
instead (that’s %HOME%\.gitconfig
in Windows):
[diff "excel"]
command = c:/apps/excelcompare/exceldiff.cmd
(See the previous post for path details and Excel Compare.)
To instruct Git to use the excel diff driver for *.xlsx files, edit
$HOME/.config/git/attributes
to contain the following:
*.xlsx diff=excel
Note that the location of the user-level gitattributes file can be configured
via the core.attributesfile
setting, so make sure you use the correct
location if you have changed that setting.
git show
By default, git show
won’t use a custom diff driver. Thus, if you show
a commit you will see the standard “Binary files … differ” message. To
get a proper diff, use the --ext-diff
option:
$ git show --ext-diff <object>
It might be a good idea to define an alias for git show
that includes
this option, for example:
$ git config --global alias.sh "show --ext-diff"
Final words
Feel free to leave a comment below if you found this post useful or if you have questions!