← Learning Hub
Beginner

status, diff and log

These three commands answer the questions you'll ask most: what's changed (status), exactly how (diff), and what happened before (log). Running git status often is the best habit for avoiding confusion.

git status - what's going on?

Example
git status
# On branch main
# Changes not staged for commit:
#   modified:   index.html
# Untracked files:
#   about.html

git diff - what exactly changed?

Example
git diff                    # changes not yet staged
git diff --staged           # changes staged for the next commit
# -<h1>Riya</h1>
# +<h1>Riya Sharma</h1>

Lines starting with - were removed and lines with + were added.

git log - the history

Example
git log --oneline
# 7c1e0b2 Add contact form
# 5d9a3f1 Style the header
# 3f2a1c9 Add home page heading

git log --oneline --graph --all     # with branches drawn
git show 5d9a3f1                    # what one commit changed
git log -p index.html               # full history of one file

Each commit has a unique id (a hash) like 5d9a3f1. You use it to look at or go back to that snapshot.

Run git status often - before adding, before committing, before switching branches. It tells you exactly where you are.
Key points
  • git status shows what's changed and staged.
  • git diff shows the exact line changes.
  • git log shows the history of commits.

📝 Test yourself

1. Which command shows changes you have staged?
2. In a diff, what does a line starting with + mean?
3. Fill in the option for a one-line-per-commit history:
git log --