1

When you invoke git diff, it's using the diff utility to compare files, however, not in the default way. It's using a number of extra options, some I can name are:

  • Different markers before lines: +/- instead of >/<.
  • A few lines of context before and after the actually different lines.

But I'm not sure these are the only changes. What are the others and what command line arguments does git pass to diff to achieve it's default output? And if I would want to compare, say, a.txt with b.txt and make the diff file the way git makes it, what command line should I use?

1 Answer 1

4

Git does not use the default *nix or GNU diff, but implements its own diff algorithm.

The code for this is located mainly in the files builtin/diff.c, builtin/diff-tree.c, builtin/diff-index.c and builtin/diff-files.c in the Git source tree.

It can thereby do some fancy things like advanced word-diff and has a reliable implementation for all platforms.

The default (line-based) unified-diff format patches it can produce are compatible with most other imlementations of the format. IIRC, GNU diff (or was it patch?) also added some more tolerance to some extras that Git puts in the diff, so as to be more resilient when applying git-generated patches.

Sign up to request clarification or add additional context in comments.

2 Comments

Can I use git's implementation of diff outside of version control to find diff of two arbitrary files?
Huhn. it turns out that you can (I first thought you couldn't). git diff -- $FILEA $FILEB seems to work even outside of git repos -- naturally, git must be installed

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.