This might be a well-known trick already, but just in case it’s not…
Reviewing a patch can be a bit painful when a file that has been changed and moved or renamed at one go (and there can be perfectly valid reasons for doing this). A nice thing about git is that you can reference files in an arbitrary tree while using git diff, so reviewing such changes can become easier if you do something like this:
$ git am 0001-the-thing-I-need-to-review.patch $ git diff HEAD^:old/path/to/file.c new/path/to/file.c
This just references file.c in its old path, which is available in the commit before HEAD, and compares it to the file at the new path in the patch you just merged.
Of course, you can also use this to diff a file at some arbitrary point in the past, or in some arbitrary branch, with the same file at the current HEAD or any other point.
Hopefully this is helpful to someone out there!
Update: As Alex Elsayed points out in the comments, git diff -M/-C can be used to similar effect. The above example, for example, could be written as:
$ git am 0001-the-thing-I-need-to-review.patch $ git show -C
February 18, 2015 — 2:33 pm
You might also be interested in the -M (track moves) and -C (track copies) options – with those, so long as the move or copy is the only change,
git diff -M -C -Cwill give the same result as your command above with a lot less typing. If there are other changes, it’ll still do the right thing – it’ll mark the diff hunk as a move, and only show the changed lines.
February 18, 2015 — 2:38 pm
Although ‘diff’ is most relevant for ‘apply’ – for ‘am’, which commits it,
git format-patch -M -C -C -1 --stdoutis a good option, as is
git log --patch -M -C -C
February 18, 2015 — 3:13 pm
Thanks for pointing this out! I guess
-M? And why the multiple
February 18, 2015 — 3:20 pm
The duplication of -C is the same as specifying -C – so -C -C is the same as -C2. It’s mostly just habit; I first learned it as -M -C -C.
February 18, 2015 — 3:22 pm
Gah, it cut out my -C<number-of-repetions>
It’s in the ‘git diff’ manpage – a higher -C number makes it ‘try harder’ to find copies.
Alexander E. Patrakov
February 20, 2015 — 11:30 am
Are you trying to review the RAOP-related patches for PulseAudio? Asking because they do contain such inconvenient-to-review code-moving.