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 syntax that usually refers to the last commit. (points to the last commit ID). [see Git: What's HEAD]

Diff Between Areas

Diff workingDir vs Index

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

Diff workingDir vs lastCommit

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

Diff Index vs lastCommit

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

Diff Between 2 Commits

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

You only need to type the first few characters of commit id.

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.


git FAQ