Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setup 'git diff' for special file types

Tags:

git

diff

I want to manage Excel files in one of my repositories. Diffing them is a problem (they are binary files). However, there is a nice tool for diffing them: https://github.com/na-ka-na/ExcelCompare

I wanted to set it up using .gitattributes

*.xls diff=excel
*.xlsx diff=excel

And in the .git/config:

[diff "excel"]
    textconv = excel_cmp.bat

The command excel_cmp.bat file1.xls file2.xls works very well. However, the setup I use above seems to try to convert the excel files to text using excel_cmp.bat and then diffs the text output.

How do I setup the diff tool to diff two files - and not to convert to text first and then diff the text output?

EDIT:

In the above setting, what git seems to do is to diff the output of excel_cmp.bat <file1> and excel_cmp.bat <file2>. But what I want is excel_cmp.bat <file1> <file2>. How can I set this up?

like image 792
Sh4pe Avatar asked Nov 19 '13 11:11

Sh4pe


People also ask

Can you git diff a specific file?

The git diff command returns a list of all the changes in all the files between our last commit and our current repository. If you want to retrieve the changes made to a specific file in a repository, you can specify that file as a third parameter.

Can git diff binary files?

Any binary format can be diffed with git, as long as there's a tool which converts the binary format to plain text. One just needs to add the conversion handlers and attributes in the same way.

What does ++ mean in git diff?

When viewing a combined diff, if the two files you're comparing have a line that's different from what they were merged into, you will see the ++ to represent: one line that was added does not appear in either file1 or file2.

Can git compare Excel files?

The extension makes git diff work for Excel VBA (xls, xlt, xla, xlam, xlsx, xlsm, xlsb, xltx, xltm). Git XL does not require Excel as it works directly on the workbook file. With Git XL installed, Git can diff Excel VBA just like any other source code file.


2 Answers

Okay, what I was looking for was the following in my .gitconfig:

[diff "excel"]
    command = excel_cmp.bat
like image 54
Sh4pe Avatar answered Sep 30 '22 15:09

Sh4pe


We've built an open-source Git command line extension for Excel workbooks: https://www.xltrail.com/git-xltrail (the repository is hosted on GitHub: https://github.com/ZoomerAnalytics/git-xltrail) which might help you. It's a simple installation process and does not require any manual plumbing work.

In a nutshell, the main feature is that it makes git diff work on any workbook file formats so that it shows the diff on the workbook's VBA content (at some point, we'll make this work for the worksheets content, too).

like image 40
Bjorn Stiel Avatar answered Sep 30 '22 14:09

Bjorn Stiel