Beginner 5 min

Git commits and diffs

Git records checkpoints so you can compare, explain, and recover changes.

How it works

Separate the working copy, the staged copy, and the commit. When you change an already staged file, the newer content is initially only in the working copy. git diff --staged lets you verify which version the commit will record.

Walk through an example

Use git status to see changed files and git diff to inspect unstaged changes. git add chooses content for the next commit, and a commit records that chosen snapshot.

What to watch for

A commit is local by default. Pushing shares it with a remote repository. Check for credentials and personal data before staging files.

Check your understanding

Does a commit automatically include the latest edit?

See the example and explanation
Worked example
Given You edit a file after staging it.
Answer No.

Git commits the staged version. Stage the latest changes too if they belong in the commit.

Open practice problem
Next lessonScope and lifetime