A commit is a snapshot of the entire repository at a single point in time, together with metadata (author, committer, date, parent commits) and a message describing what changed. Commits are git's fundamental unit of history: a repository is a directed acyclic graph of commits, each pointing to its parent (or parents, for merge commits).
The basic commit workflow:
git status # see what's changed
git add file.txt # stage a change
git add -p # stage hunks interactively
git commit -m "Fix bug in parser" # commit staged changes
git commit -a -m "..." # stage all tracked and commit
git log # view history
git log --oneline --graph --all # compact graph view
git show HEAD # inspect the last commit
Good commit discipline is central to productive git use: commits should represent logically coherent changes, have descriptive messages, and build and pass tests on their own where possible. The subject line is traditionally kept under 50 characters, followed by a blank line and a wrapped body explaining why the change was made.
Commits are identified by a 40-character SHA-1 hash (abbreviated to the first 7-8 characters in display). This hash depends on the commit's contents and parents, so any change to history produces new hashes—which is why rewriting published history is considered rude.
Related terms: Git, Git Branch, Git Repository
Discussed in:
- Chapter 16: Version Control with Git — How Git Thinks
Also defined in: Textbook of Linux