Looking at Previous git Commits

You want to know the changes that were committed with a particular commit at some arbitrary point in the past. First, find the commit ID:

git log

From the log you determine the ID of the commit you're interested in was "aabbcc112233".

Don't use:

git diff aabbcc112233

That will show you the difference between that version and HEAD - probably not what you wanted! Although it's useful in some contexts.

git show aabbcc112233

This will show all changes applied by that commit.

If you want to do it with diff, you can:

git diff aabbcc112233^ aabbcc112233

The result is very similar, but this is a useful format to know: you're diffing two different commits, where "aabbcc112233^" is "the commit before aabbcc112233". Using git diff (with no parameters) when you have uncommitted changes is great, but it doesn't work once the commit is made. What are the last set of changes that were committed?:

git diff HEAD^ HEAD

"HEAD" is a special commit, the current state of the repo, and "^" effectively decrements by one. This can be extended by using "HEAD^^", "HEAD^^^", etc.


I admit it: I'm restating and extending stackoverflow content ... Thanks, once again, stackoverflow: