Git Reference ยท Objects, Refs and Internals
Commit objects
Reference for the Git commit object: tree, parent, author and committer headers, optional encoding and gpgsig headers, the message, and how to build one by hand.
A commit object ties a snapshot to its history. It stores the ID of one tree (the snapshot), the IDs of zero or more parent commits, who wrote and who committed the change with a time stamp for each, and the message. Nothing else: no diff, no branch name, no list of changed files. Everything you see in git log or git show is derived by comparing trees.
A commit is plain text. Because its ID is computed from that text, changing any part of it (the message, a date, the parent, or the tree) gives a different ID. That is the reason rewriting a commit rewrites all of its descendants.
git cat-file -p HEAD # show the raw commit git cat-file commit HEAD # same, without pretty-printing git commit-tree <tree> -p <parent> -m "message"
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Format
The object body is a block of headers, one blank line, and the message:
tree <tree-id> parent <parent-id> (zero or more lines) author Name <email> <unix-time> <zone> committer Name <email> <unix-time> <zone> encoding <name> (optional) gpgsig <signature> (optional, continued lines start with a space) mergetag <embedded tag> (optional) <message>
| Header | Description |
|---|---|
tree |
The ID of the root tree. Exactly one, always first. |
parent |
One line per parent. None for a root commit, two or more for a merge. The order matters: the first parent is the branch you merged into. |
author |
Who wrote the change, plus the time and zone when it was first written. |
committer |
Who created this commit object, with its own time. It differs from the author after cherry-pick, rebase, am or commit --amend -C. |
encoding |
Only present when the message is not UTF-8 (set by i18n.commitEncoding). |
gpgsig, gpgsig-sha256 |
A signature over the commit; see Signed commits and tags. Continuation lines begin with a single space. |
mergetag |
A copy of a signed tag that was merged with git merge, kept as evidence. |
The time is seconds since the Unix epoch in decimal, followed by a zone offset such as +0200 or -0800. Names and addresses are free text; the address is wrapped in angle brackets. The message is everything after the first blank line, stored exactly as written, normally ending with a newline.
Usage notes
- A commit is not a diff. Parents let Git compute one on demand:
git showcompares the commit's tree with its first parent's tree. - Author versus committer. Set
GIT_AUTHOR_*andGIT_COMMITTER_*separately (see Author and committer variables) to control each;git log --format=%an,%cnprints both names. - Parent order.
HEAD^1andHEAD^2follow the parent lines in order. Octopus merges list three or more. - Unknown headers are kept. Git ignores headers it does not know, which allows tools to add their own;
git fsckstill checks the standard ones. - Notes live elsewhere. Data added later with
git notesis stored on a separate ref and does not change the commit's ID. - Grafts and replacements (
git replace) change what Git shows, not the stored object. - First line convention. The first line is the subject, shown by
--oneline. The blank line after it is a convention of tools, not a rule of the format.