What did I do? Read status, log and diff

safe beginner #status#log#diff#history#review

When to use this: You came back to the project after a while and need to know where things stand and what you changed.

Before you start

Steps

  1. Where am I and what is uncommitted?

    terminal
    git status -sb

    -s is the short format, -b adds the branch line. ahead 2 means 2 commits not pushed; behind 1 means GitHub has 1 you do not.

    Expected output
    ## feature-hero...origin/feature-hero [ahead 2]
     M src/styles/global.css
    A  src/pages/about.astro
  2. What have I committed recently?

    terminal
    git log --oneline --graph --decorate -n 15

    One line per commit, newest first. HEAD -> branch marks where you are and origin/main shows where GitHub is. Press q to leave the pager.

    Expected output
    * 8c4d7e0 (HEAD -> main, origin/main) Add Vercel domain scenario
    * 3f2a1b9 Fix broken link on home page
  3. What exactly did I change (not staged yet)?

    terminal
    git diff

    Shows line-by-line edits in your working tree. Lines starting with - were removed and + were added.

  4. What is staged and ready to commit?

    terminal
    git diff --staged

    The same view, but only for what git add has staged.

  5. What did one commit contain?

    terminal
    git show 8c4d7e0 --stat

    Replace the ID with one from git log. --stat lists files changed; drop it to see the full diff.

How to verify it worked

  • You can answer: which branch am I on, what is uncommitted, and what is unpushed.

Common errors and fixes

The terminal seems frozen on a : or (END) That is the pager. Press q to quit. To avoid it, add --no-pager after git, or run git config --global core.pager cat.
git diff shows nothing but status shows changes The changes are staged. Use git diff --staged.

Q&A

What do M, A, ?? mean in git status -s?

M modified, A added (new and staged), D deleted, ?? untracked (new and not staged). The left column is the staging area, the right column the working tree.

What does HEAD~2 mean?

Two commits before HEAD. git show HEAD~2 shows that commit.

Practice these as flashcards →

Terms in this scenario

Related scenarios

My notes

Saved in this browser only.