~/
Viewing Changes
Quiz
...

Viewing Changes

beginner · updated Tue Sep 08 2026Contribute

Learn how to use git diff to track changes in your code effectively, both before and after staging files for a commit.

Viewing Changes

git diff shows what changed between different states of your repository. It’s essential for reviewing changes before committing.

Unstaged Changes

See changes not yet staged:

git diff
# diff --git a/file.txt b/file.txt
# --- a/file.txt
# +++ b/file.txt
# @@ -1 +1 @@
# -old line
# +new line

Staged Changes

See changes that are staged for commit:

git diff --staged

All Changes

See everything (staged and unstaged):

git diff HEAD

Statistical Summary

Get a quick overview of what changed:

git diff --stat
# file.txt | 2 +-
# 1 file changed, 1 insertion(+), 1 deletion(-)

Reading Diff Output

  • - lines show what was removed
  • + lines show what was added
  • @@ shows the line range affected
  • Colors help distinguish additions (green) from deletions (red)

Best Practices

  • Review changes with git diff before staging
  • Use git diff --staged before committing
  • Use git diff --stat for quick overviews
  • Compare specific commits with git diff commit1 commit2

Common Mistakes

  • Not reviewing changes before committing
  • Confusing staged and unstaged diffs
  • Ignoring whitespace changes that affect functionality
  • Not using diff to understand merge conflicts