Git Commits and Tag Objects
A commit is more than a snapshot
A commit contains a root tree ID, zero or more ordered parent IDs, author and committer information, and a message. A root commit has no parent. An ordinary commit has one; a merge has multiple parents. Two commits can reference the same tree while having different messages, parents or metadata and thus different identities.
Follow a commit
In the fixture, main ends at a merge after resolving a conflict. Read its payload with cat-file. The tree line identifies the snapshot, the parent lines identify ancestry in order. Author and committer fields do not establish account authentication. Inspect the root and merge separately.
git cat-file -p basegit cat-file -p HEADgit rev-list --parents -n 1 HEADTwo kinds of tags
A lightweight tag is a ref pointing directly at an object. An annotated tag points at a tag object which records a target, target type, tag name, tagger and message (and optionally a signature). A tag object can target a non-commit object too. Peeling an annotated tag with ^{} follows tag objects to a non-tag target; ^{commit} requires a commit.
git cat-file -t basegit cat-file -t release-demogit cat-file -p release-demogit rev-parse "release-demo^{commit}" HEADPractice and check
The fixture creates base as a lightweight tag and release-demo as an annotated tag at the merge. Expect types commit and tag, respectively, and matching peeled release and HEAD IDs. An annotated tag is not automatically signed or published.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Git Commits and Tag Objects — knowledge check
Reason about Git objects, index and reference state.
What directly identifies a commit snapshot?
How many parents does a root commit have?
What can differ between commits with the same tree?
What type does an annotated tag ref normally point to?
What does TAG^{commit} require?