Git Commit: A Snapshot, Not a Diff
A Git commit is a permanent snapshot of your entire project, not just the changes. It's a save point containing the full state of all files, linked to the previous commit to form a historical chain.
Why it exists
Git needs a way to record the history of a project. A commit is the fundamental unit for this history, acting as a permanent, verifiable record of the project's state at a specific point in time, allowing developers to track changes and collaborate effectively.
The mental model
A Git commit is a permanent snapshot of your entire project, not just the code that changed. Think of it as a save point in a video game. It contains the complete state of all tracked files and a pointer to the previous save point (the parent commit), forming a chain of history.
How it works
A commit is a Git object with a unique ID, which is a cryptographic hash of its contents, making it immutable. Each commit object stores several key pieces of information: first, a reference (a "tree" ID) to the project's complete directory structure and file contents at that moment; second, the ID of its parent commit(s); third, an author and timestamp; fourth, a committer and timestamp; and fifth, a descriptive commit message.
When to use it
Create a commit when you have completed a logical unit of work. This could be fixing a single bug, adding a small feature, or updating documentation. These commits become the building blocks of your project's history, used in branches, merges, and pull requests to manage development.
When not to use it
Avoid creating commits for half-finished or broken work on shared branches; use the staging area for intermediate saves. Because commits are part of the permanent record, never commit sensitive data like API keys or passwords. Once committed, it's difficult to truly erase that information from the repository's history.
One canonical example
When you fix a typo and commit, you create a new commit object with one parent: the commit you were on before the fix. A special case is a merge commit, which has two or more parents, created when you join two separate lines of history. The very first commit in a repository is also special, as it has no parents.
Interview question
What does a Git commit fundamentally represent?
- a.A record of only the differences between the current state and the previous commit.
- b.A temporary collection of changes staged for potential future saving.
- c.A complete snapshot of all tracked files in the project at a specific point in time.Correct
- d.The descriptive message, author, and timestamp associated with a set of modifications.
Why? this is the answer
A Git commit is described as a 'permanent snapshot of your entire project,' containing the complete state of all tracked files. Option A is a common misconception, as Git stores full snapshots, not just diffs. Options C and D describe aspects of the commit process or metadata, not the core content of the commit itself.
Just read this? Test yourself on what you have been reading.
Read the original → github.com
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on git — each one lists the topics its interview covers.
See open roles