Hone

Lessons · Git · what changed, line by line

Seeing the change before you record it

git diff shows working-tree edits that are not staged. git diff --staged shows what is staged, which is exactly what the next commit will contain.

Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.

What it is for

Reading the diff before committing catches the debug print, the stray file and the half-finished edit. It is code review of yourself, thirty seconds, every time.

How to think about it

Two questions, two commands: what have I changed that is not staged (diff), and what am I about to commit (diff --staged). If diff shows nothing after add, the change moved to --staged.

Worked example

echo change >> a.txt
Edit a tracked file.
git diff
Working tree against the index: the edit shows as a + line, unstaged.
git add a.txt && git diff
Nothing: the change is staged now.
git diff --staged
Index against the last commit: what the next commit will contain.

Your turn

Review what the next commit will contain.

git diff 

The trap

git diff after git add shows nothing and looks like the change vanished. It moved to --staged.

Practise what changed, line by line on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.