Git Refs and Revision Disambiguation
Resolve a name before using it
A revision expression is a name Git interprets as an object or, in history commands, a set of commits. A branch reference identifies its tip; HEAD usually points symbolically to the current branch. In the chapter 20 lab, a branch and a tag both use the name shared but identify different commits. Use fully qualified ref names to avoid ambiguity. Run the setup in lab-fixtures/chapter20-guide.md first. All subsequent examples refer to that disposable repository.
git symbolic-ref HEADgit rev-parse --verify refs/heads/sharedgit rev-parse --verify refs/tags/sharedRead the object identity
In the fixture main points to M, shared branch points to C and shared tag points to E. A bare shared name produces an ambiguity warning and resolves to the tag in this fixture; do not rely on precedence. Use show-ref --verify for exact reference existence. An abbreviated hash is acceptable only if Git can resolve it uniquely. Full object ID length depends on repository object format, so do not assume 40 characters everywhere.
git show-ref --verify refs/heads/sharedgit rev-parse --short Mgit rev-parse --verify --end-of-options "release-mark^{commit}"Peel a tag and select a historical file
The annotated tag release-mark names a separate tag object. The suffix ^{commit} requires a commit after dereferencing; ^{} removes tag layers and ^{tree} selects a tree when possible. D:notes.txt names the blob at that path in D, rather than a file on disk. The commands below report tag, blob and Water every 3 days. Use --verify --end-of-options with a quoted expression when accepting a name from elsewhere; a successful resolution does not grant authorization or prove the intended object was chosen.
git cat-file -t release-markgit cat-file -t D:notes.txtgit show D:notes.txtPractice: choose the unambiguous expression
Predict which ref gives C and which gives E. Then verify that release-mark^{commit} resolves to M. Compare the full IDs rather than relying on their visual prefixes. These inspection commands do not change files or history. Next, traverse parent relationships.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Git Refs and Revision Disambiguation — knowledge check
Predict revision resolution, commit sets and path selection.
Which expression selects the shared branch in the fixture?
What does release-mark^{commit} resolve to?
When is an abbreviated object ID usable?
What does D:notes.txt identify?
What does --end-of-options protect against in rev-parse verification?