Menu
CoddyTech

Diff The Staged Changes

Part of the Version Control section of Coddy's Terminal journey. Lesson 16 of 58.

Once you stage changes with git add, plain git diff stops showing them. To see what is queued up for the next commit, use:

git diff --staged

(The flag --cached is an alias and does the same thing.) This is what you should run right before committing, to double-check exactly what will be saved.

The two diffs answer two different questions:

  • git diff: "what have I changed but not yet staged?"
  • git diff --staged: "what will go into the next commit?"

If you have both unstaged edits and staged edits, the two commands show different sets of lines. Knowing which is which prevents you from committing the wrong version.

challenge icon

Challenge

Easy

The folder contains config.txt with the content port=80. Commit it as it is, change it to port=8080, stage the change, then run git diff --staged.

Every run starts from a fresh copy of the folder, and the whole script in the editor runs again from the top. Nothing is committed for you: begin with git init -q -b main, set git config user.name and git config user.email, and commit the starting file. Keep those lines in the editor. If you clear them you will see fatal: not a git repository.

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Version Control

Practice on your own: Terminal playground