Lesson 8 +10 XP

Git Commit

Git Commit

A commit is a saved snapshot of your project. It is the core of how Git records history.

Commit your staged changes

git commit -m "Add landing page"

The -m flag adds a message that describes what you changed. Always write a short, clear message so future you (and your team) understand the history.

Commit and stage in one step

To stage everything and commit in one command:

git commit -am "Update styles"

The -a flag stages all changes to already tracked files before committing. Note: it does not stage brand new files.

Check the result

git status

After a commit, Git tells you your working tree is clean, meaning everything is saved.

What is inside a commit?

  • A snapshot of your files.
  • Your name and email (from your config).
  • A timestamp.
  • A unique ID called a hash.
  • A message.

TL;DR

  • git commit -m "message" saves a snapshot.
  • git commit -am stages and commits in one step.
  • Each commit has a hash, author, timestamp, and message.
  • git status confirms your work is saved.