Git Commit: Save a Meaningful Snapshot
Create a commit from the index
A commit records a tree of selected project contents together with metadata and parent information. In the normal git commit -m workflow, Git takes the snapshot from the index; it does not automatically include all edits on disk. Continue with Tea and Rice staged from lesson 2. Review the diff before committing.
git diff --cached -- notes.txtgit commit -m "Add grocery notes"git status --shortThe commit reports a root commit on main. Its identifier varies with metadata. Short status is empty because the file matches the new commit and index. No network or GitHub account is needed.
Inspect the recorded snapshot
The branch now points to the new commit. HEAD normally refers to that branch in this lab. Inspect the recorded message and file without changing the working tree.
The message is Add grocery notes; the recorded file contains Tea and Rice on separate lines.
Make the next change focused
A useful message says what changed, and a commit should group related work. Avoid vague messages such as update if you can describe the intent. Add one item, then inspect rather than committing immediately. A normal commit with no staged changes will not create a new commit by default; special options exist but are not needed here.
Expected: M notes.txt (leading space). Practice: propose a useful message for adding Milk. Do not stage it yet; this is the starting state for lesson 4.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Git Commit: Save a Meaningful Snapshot — knowledge check
Apply the lesson to common beginner repository states.
What does an ordinary git commit -m record?
Which message best describes adding Milk to a grocery list?
Which command reads the committed notes.txt without changing the working file?
Does the local commit require a GitHub account?
After a successful commit with all changes staged and no other edits, what should short status show?