This flag is the magic sauce that lets us use git diff with files that are not source controlled.
-- $1 $2
These are just passing the filepaths down to git so it knows where to look.
Nice extra features.
Tells git to print the output to stdout instead of opening a paging program. Note: this flag must come before diff
Preserves the diff colors when you pipe to other programs, e.g. grep which you may not want!
--src-prefix="old = "
--dst-prefix="new = "
Tells git to display the file names as "old" and "new" instead of "a" and "b". Very much a personal preference.
Allows you to pass further arguments to git diff. See below for some examples.
You can read about all of the possible flags that can be passed to git diff by consulting git help diff.
Here we'll use the following two files, old.txt and new.txt.
Running fdiff on these files produces output like this.
Diffs on words
For day-to-day usage, I find --word-diff or --color-words the most useful.
If you just want an overview of diffs, you can use flags like --compact-summary or
Seeing Where Text Moved
If you're writing a longer document and you want to see where pieces have moved, you can use
--color-moved=plain. Here I'm no longer using our previous example files.
You can specify the number of lines of context (lines before and after) you want with the -U flag.
So for 0 lines of context, use -U0. For 10 lines, -U10, etc. I often use this in
combination with --word-diff.