Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
What is a Repository  ›  Lesson

Committing Changes

Committing Changes 12 minA commit is a snapshot of the staged files with author, time, message and a link to its parent, and each commit should hold one idea with a clear message.

Committing Changes

A commit is the snapshot that actually lands in history. Asha will read her commits months from now, so each one should be a single, clear step: one idea, one message.

The rule

One commit, one idea, with a message that finishes "This commit will…".

After staging, record the snapshot:

git add pancakes.md
git commit -m "Add baking powder amount to pancakes"

Each commit stores:

  • a snapshot of every tracked file as it was staged,
  • the author (from user.name and user.email) and the time,
  • the message,
  • a link to its parent commit, the one before it. That link is what turns separate snapshots into a history.

Git gives every commit a unique ID, a long hash such as 4f9c2e1…. The first seven or so characters are usually enough to name it.

Good messages are short, specific and written as a command: "Add chai recipe", "Fix oven temperature in bread", "Remove duplicate salt line". A handy test: the message should complete the sentence "If applied, this commit will…". Messages like "stuff", "fix" or "changes" tell future readers nothing.

Keep commits focused. If you fixed a typo and also rewrote a recipe, stage and commit them separately. A focused commit is easy to understand, easy to review and easy to undo on its own.

Two handy variations:

git commit                  # opens your editor for a longer message
git commit -am "Tweak chai sugar"   # stages every modified tracked file, then commits

-a only includes files Git already tracks. A brand-new, untracked file still needs git add first.

If you run git commit with nothing staged, Git reports that there is nothing to commit and makes no snapshot.

The shortcut

Before committing, read your staged changes with git diff --staged and say the message out loud. If you need the word "and", it is probably two commits.

Two ideas, two commitsStep 1 of 4
  1. What changed?

    Asha added bread.md and also fixed the sugar amount in chai.md.

The trap is the giant end-of-day commit named "update". It works today and becomes useless the first time you need to find or undo one specific change.

Drills

Answer fast — trust the rule.

quick drill

Which is the most useful commit message?

quick drill

What links one commit to the commit before it?

quick drill

Asha creates a new file soup.md and runs git commit -am "Add soup". What happens to soup.md?

quick drill

Asha's message would be "Rename muffins file and fix typo in README". What does the shortcut suggest?

Remember

  • One commit, one idea, with a message that finishes "This commit will…".
  • Read git diff --staged first; if the message needs "and", split it.
  • -a stages modified tracked files only; new files still need git add.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainSplit the day's work

By the end of the day Asha has added bread.md, fixed a typo in README.md and changed the sugar in chai.md. Explain how you would commit this work, including the messages you would write and why.