Developer workflow · ToolTrap learning guide
Git: review a change before you commit it
Understand working files, staged changes and commits using a two-file exercise, then choose a safe way to unstage a file.
Think in three snapshots
Suppose you updated a README and a configuration file, but only the README is ready to share. Git does not have to commit every edited file together. Your working tree is what you are editing; the staging area is the proposed next snapshot; a commit records the staged snapshot in history.
Try this in a disposable repository with an existing first commit. Edit README.md and config.txt, then run these commands. If your practice files have different names, substitute their paths explicitly.
git status --short
git diff -- README.md config.txt
git add README.md
git diff --stagedThe ordinary diff shows unstaged edits; the staged diff shows what the next commit would include. Read the staged diff before committing. In this exercise it should include the README change and leave the configuration edit out.
Unstage without throwing away your work
Now imagine you accidentally staged config.txt as well. You want it out of the proposed commit, but you still want the edited file on disk. Restoring only the staging area achieves that. The --staged option is the part that makes this different from discarding a working file's edits.
git add config.txt
git restore --staged config.txt
git status --short
git diff -- config.txtThe configuration changes should still appear in the working-tree diff. Avoid adding --worktree to this command when your goal is simply to unstage. Before using any command that replaces working files, keep a copy or commit work you need to preserve.
A staged file can change again
Staging captures a file's content at that moment. It does not freeze the editor. If you stage the README and then change another sentence, the staged version and the working version differ. Use both diff commands to see this rather than assuming the latest visible text will be committed.
When you are satisfied, stage the intended final README content again, inspect git diff --staged, and make a focused commit. A message such as Explain local setup tells a teammate more than Update files. Check git status afterward to see what remains uncommitted.
git add README.md
git diff --staged
git commit -m "Explain local setup"
git status --shortCheck your understanding
Question 1: You edit two files and stage one. How many of those files does the next commit include? Answer: one, assuming there are no other staged changes.
Question 2: Does git restore --staged config.txt erase its edited contents? Answer: no. It changes the index; your working file remains available to inspect and edit.
Question 3: You edit a file after staging it. Does the commit automatically include those new edits? Answer: no. Stage the new content deliberately if it belongs in the commit.
For your next real change, take thirty seconds to check status, read the working diff, stage selected paths, and read the staged diff. That short routine catches unrelated edits and makes reviews easier to follow.
Explore the official documentation
Use these references to check command options and continue your practice.