Committing Changes

How to save your staged files into a permanent snapshot in the Git history.

Version Control4 min readConcept 5 of 29

What is a Commit?

A commit is a permanent snapshot of all your staged files at a specific point in time. It is the fundamental building block of Git's 'Time Machine'.

When you run git commit, Git takes everything currently in the Staging Area, packages it into an immutable snapshot, and adds it to the repository's history timeline.

Why it matters

Commits are your safety net. If you make a terrible mistake tomorrow, you can instantly revert your codebase back to a commit you made today.

Furthermore, every commit requires a 'commit message'. These messages act as a logbook for your project, explaining *why* a change was made to your future self or other developers.

The structure of a commit

Every commit in Git contains three critical pieces of information:

1. **The Snapshot**: The actual files and folder structure at that exact moment.

2. **The Metadata**: Who made the commit (Author), when they made it (Date), and the commit message.

3. **The Hash**: A unique 40-character alphanumeric ID (like 9fceb02d...) that acts as the commit's permanent name.

Check yourself

Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.

  1. 1What does the `git commit` command actually do?
  2. 2Which of the following is considered a 'good' professional commit message?
  3. 3What is the 'Hash' (or SHA) of a commit?

Remember this

  • git commit -m 'Message' creates a snapshot.
  • Only staged files are included in the commit.
  • Write messages in the imperative mood ('Fix bug' not 'Fixed bug').

Done with this concept?

Mark it complete to track your progress. No login needed.