Skip to content

Instantly share code, notes, and snippets.

@phil-a
Forked from PrabhatKJena/git-diff-spreadsheet.md
Created February 19, 2020 17:14
Show Gist options
  • Select an option

  • Save phil-a/fe9e4644a3a34afd8c1bf6e1b2b6f41c to your computer and use it in GitHub Desktop.

Select an option

Save phil-a/fe9e4644a3a34afd8c1bf6e1b2b6f41c to your computer and use it in GitHub Desktop.
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment