Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to git diff for MS-Excel files(xls/xlsx) on Mac-OS

How to git diff for MS-Excel files(xls/xlsx) on Mac-OS

Installation

Prerequisites

  • Requires Java 1.6 or higher.
  • Assumes Java is added to PATH (to check open a cmd and run java -version)
  • No other platform specific requirements
  • A shell script and a bat script are packaged

Just download the zip file.

Extract it anywhere (and optionally you add the bin folder to PATH).

macOS

Homebrew makes it easy to install ExcelCompare:

$ brew update
$ brew install excel-compare

All what you have yo do

  1. Create exceldiff.cmd command file anywhere with write permission and add the following to it:
    <path-to-the-excel-compare-installation-folder>/bin/excel_cmp $2 $5
    e.g.
    /usr/local/Cellar/excel-compare/0.6.1/bin/excel_cmp $2 $5

    Why arguments two and five? It’s because Git passes seven arguments to a diff command, of which the second is the path to the old file (which likely is a temporary file) and the fifth is the path to the new file. For more detailed information, have a look at the Git documentation, specifically under GIT_EXTERNAL_DIFF.

  2. Edit the .git/config file in your repository and amend the following path:
    [diff "excel"]
    command = <path-of-the-command-file-above>

    e.g.
    [diff "excel"]
    command = /usr/local/Cellar/excel-compare/0.6.1/bin/exceldiff.cmd

  3. Next, we must tell Git to associate certain files with the excel diff driver. To do so, edit .gitattributes in the root of your repository and amend the following:
    *.xlsx diff=excel
    *.xls diff=excel

Note:

  • Git attributes are set either in a .gitattributes file in one of your directories (normally the root of your project) or in the .git/info/attributes file if you don’t want the attributes file committed with your project.
  • .gitattributes (unlike .gitignore) must be committed to have any effect, so add it to a commit at this point.

Usage

  • Compare with HEAD revision
    git diff <file_name>
  • Compare file between 2 commits
    git diff <left_commit_id> <right_commit_id> <file_name>
@mcculley

This comment has been minimized.

Copy link

mcculley commented Apr 17, 2019

Where you describe how to get git to recognize the .xlsx and .xls file extensions, I had to use *.xlsx diff=excel instead of .xlsdiff excel and do similar for .xls.

@PrabhatKJena

This comment has been minimized.

Copy link
Owner Author

PrabhatKJena commented Jun 23, 2019

Thank you @mcculley and @stefjoosten for the feedback. I will update the instruction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.