Git: Show Difference Between Files

By Xah Lee. Date: . Last updated: .

Here's how to diff between various areas of git.

here's some important concepts of areas/states for diff to work on (All are local on your computer):

Working Directory (aka Working Tree)
Files in your project's directory.
Index (aka Staging Area)
A virtual area (a index file) that git add is placed into.
Commit ID
A specific commit. [see Git: Commit ID]
A variable that usually refers to the last commit of current branch. [see Git: What's HEAD]

Diff Between Areas

Diff workingDir vs lastCommit

git diff --color commitID
diff workingDir vs lastCommit. Replace the commitID by HEAD, for lastCommit.

Diff Between 2 Commits

git diff ID1 ID2 filename
diff between 2 commits. [see Git: Commit ID]

Diff workingDir vs Index

git diff --color
diff workingDir vs Index
git diff --color filename
diff workingDir vs Index, 1 file

Diff Index vs lastCommit

git diff --color --staged commitID
diff Index vs lastCommit

Show Changed Files

git status
Show state of {Index, workingDir, lastCommit}
git status sample 2021-01-31
git status sample 2021-01-31

2014-01-18 Thanks to Nick Alcock for review.