🎓 A1Learner
🔍
0 of 50 lessons completed

Make a Commit

A commit saves a snapshot. It records the staged changes with a message and a name.

Save the snapshot

The message says what the snapshot holds.

$ git commit -m "Add shopping list"

List the snapshots

One line names the snapshot and its message.

$ git log --oneline

Example

$ git commit -m "Add shopping list"
$ git log --oneline

Key points

  • Commit saves only what is staged.
  • The message says what changed and why.
  • Git prints the new snapshot’s short hash.
  • The short hash is a few letters and numbers.
  • Git uses the hash as the snapshot’s name.
  • The log command lists the snapshots you saved.
  • A commit is a promise: this state worked.

Here, commit saves the staged file. The words “root-commit” mean this is the first snapshot in the repository. The log then lists it by its short hash, 31f801f.

Note

Commit often. Small snapshots are easy to understand.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

Which command saves a snapshot?