Recording Snapshots: git commit and Semantic Commit Messages0%

Recording Snapshots: git commit and Semantic Commit Messages

Beginner12 min read•Updated: Jul 11, 2026
Study MaterialsCheatsheet

Recording Snapshots: git commit and Semantic Commit Messages

Once you have staged your desired changes, the next step is to record them permanently in the repository object database using git commit. A commit represents a cryptographic snapshot of your project at a specific instant in time.


1. How git commit Works

When you commit, Git:

  1. 1
    Takes the files currently in the Staging Area (Index).
  2. 2
    Creates a tree object representing the directory structure.
  3. 3
    Packages author metadata, committer timestamp, commit message, and pointers to parent commits into a Commit Object.
  4. 4
    Computes the 40-character SHA-1 hash for this commit.
  5. 5
    Advances the current branch pointer (and HEAD) to point to the new commit.
Output
Commit Object Hierarchy:
+-------------------------------------------------------------+
| Commit Hash: 7b3f81e... |
| Author: Sumit Sharma <sumit@mskinstitute.com> |
| Date: Mon Sep 15 10:30:00 2026 +0530 |
| Parent: 4a2c91d... |
| Message: feat(auth): add JWT token expiration check |
| Tree: 9f1e82b... --> [ Blobs & sub-trees for all files ] |
+-------------------------------------------------------------+

2. Basic Commit Commands

A. Committing with an Inline Message (-m)

The most common everyday command:

Bash / Terminal
git commit -m "Add responsive navigation bar for mobile screens"

B. Committing via Text Editor (Multi-line Commits)

Omitting the -m flag opens your configured editor (VS Code, Nano, Vim) to write a detailed multi-line message:

Bash / Terminal
git commit

C. The Shortcut: Stage Tracked Files & Commit (-am)

If files are already tracked (previously committed) and you simply edited them:

Bash / Terminal
# Automatically stages all tracked modified files AND commits in one shot
git commit -am "fix: correct typo in checkout pricing calculation"
Important Warning
[!CAUTION] -a only stages modified tracked files! It will not stage newly created (untracked) files.

3. Amending the Last Commit (git commit --amend)

Have you ever committed, only to realize 5 seconds later that you forgot to include one file, or made a spelling mistake in your commit message? Instead of creating a messy follow-up commit like "oops forgot this file", you can amend the most recent commit:

Bash / Terminal
# 1. Stage the forgotten file
git add forgotten_file.css
 
# 2. Amend the previous commit without changing the message
git commit --amend --no-edit
 
# Or amend both code and update the commit message:
git commit --amend -m "feat: complete navbar styling with mobile drawer"
Important Warning
[!WARNING] Only amend commits that exist purely on your local machine! Never amend or rewrite commits that have already been pushed to a shared remote branch on GitHub.

4. Professional Semantic Commit Conventions (Conventional Commits)

Top engineering teams (and open-source projects) adhere to the Conventional Commits specification:

Output
<type>[optional scope]: <description>
 
[optional body]
 
[optional footer(s)]

Common Standard Types:

TypePurposeExample
featA brand new feature for the userfeat(auth): support Google OAuth login
fixA bug fixfix(cart): prevent negative discount calculation
docsDocumentation changes onlydocs(readme): update deployment instructions
styleFormatting, missing semi-colons, whitespacestyle(css): reorder media queries with prettier
refactorCode restructure that neither fixes bugs nor adds featuresrefactor(db): extract connection pool singleton
perfCode change that improves performanceperf(search): debounce live search input by 300ms
testAdding or correcting unit/integration teststest(auth): add unit test for expired JWT token
choreBuild system, dependency updates, toolingchore(deps): bump tailwindcss to v4.0

Interactive Quiz

Practice Quiz

Question 1
What is a Git commit?
Question 2
What does the command git commit -m "message" do?
Question 3
What is the limitation of using git commit -am "message"?
Question 4
When is it safe to use git commit --amend?
Question 5
In Conventional Commits, which type is appropriate for a commit that updates third-party npm or pip dependencies?
Next Lesson

Inspecting Commit History with git log and Formatting Flags

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext