Is it possible to get git to produce a diff between a specific file as it exists now, and as it existed before the last commit that changed it?
That is, if we know:
$ git log --oneline myfile
123abc Fix some stuff
456def Frobble the foos
789dba Initial commit
git diff 456def myfile
It appears to me that the closest thing to what you're asking for is actually:
git log -p [--follow] [-1] <path>
--patch) is hidden deeeeeeeep in the
git-log man page, and is actually a display option for
git-diff. When used with
log, it actually shows the patch that would be generated for each commit, along with the commit information--and hides commits that do not touch the specified
(This behavior is described in the paragraph on
--full-diff, which causes the full diff of each commit to be shown.)
-1, this shows all non-zero diffs of the specified file; with
-1, it shows just the most recent change. (
-n 1 can be used instead of
--follow is required to see changes that occurred prior to a rename.
As far as I can tell, this is the only way to immediately see the last set of changes made to a file without using
git log (or similar) to either count the number of intervening revisions or determine the hash of the commit.
To see older revisions changes, just scroll through the log, or specify a commit or tag from which to start the log. (Of course, specifying a commit or tag returns you to the original problem of figuring out what the correct commit or tag is.)
Credit where credit is due:
log -pthanks to this answer.
-n 1option and atatko for mentioning the