Progress:
TIER 3 · MODULE 35· Expert

git name-rev

Reverse of rev-parse: SHA in, name out.

🎯 What & why

Given a commit SHA, print a human-readable name for it like main~3 or tags/v1.2~5. The reverse direction of rev-parse.

🧠 Mental model

Walks refs backwards looking for the nearest named ancestor, then expresses your commit as an offset from it. Great for log output, awful as a stable identifier (the name shifts as refs move).

🛠️ Synopsis

git name-rev [--tags] [--refs=<pattern>] [--exclude=<pattern>]
            [--all] [--annotate-stdin] [--name-only]
            [--no-undefined] [--always]
            <commit>...

🎚️ Switches & options

FlagWhat it does
<commit>...Commits (or anything resolving to one) to name.
--tagsUse only tags as anchors; ignores branches.
--refs=<pattern>Restrict anchors to refs matching a glob, e.g. refs/tags/v*.
--exclude=<pattern>Skip refs matching the glob (pair with --refs).
--allName every commit reachable from any ref; useful for bulk annotation.
--annotate-stdinRead stdin and append a name after each SHA-shaped token (replaces older --stdin).
--name-onlyOutput just the name, not the SHA + name pair.
--no-undefinedFail instead of printing undefined for unreachable commits.
--alwaysFall back to an abbreviated SHA when no name is found.

💡 Use cases

🧪 Examples

Name a single commit
git name-rev abc1234
Name only against tags
git name-rev --tags --name-only abc1234
Annotate a log stream
git rev-list --max-count=20 HEAD | git name-rev --annotate-stdin
Restrict to release tags
git name-rev --refs='refs/tags/v*' HEAD~50

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.