Git Diff

The git diff command is for performing a terminal based difference between two states.

Command Description
git diff this will just diff unstaged files, the changes made and not staged
git diff --cached staged compare last committed to staged
git diff --staged better to use --cached as staged is just a synonym of this
git diff --no-renames this is handy when git thinks a file has been renamed but it has not
git diff --patch=patchfile.txt often used with other options but writes output to file, not console
git diff --name-only just the files that have changed, just their names
git diff HEAD changes between staged the last commit CHECK]
git diff HEAD^ one before last commit]
git diff HEAD^^ one before the one before the last commit]
git diff HEAD~5 five commits ago]
git diff HEAD^..HEAD compare second most recent to most recent
git diff branch-a..branch-b output in patch file format what is in branch-b that is not in branch-a
git diff branch-a...branch-b same as above but three dots means changes from common ancestor
git diff b76g76cc..145bgf8d difference between two commits

It is worth noting that you can also use tags and SHAs when doing a diff as well as dates.

Another point to note is that in one sense git does not care about filenames, what it does care about is file contents and the SHA1 hash of the content. This is especially relevant when working with git diff as it will detect the renaming of a file because it sees the content is identical, which is why --no-renames can be useful.

See also: