GIT-NAME-REV(1)

πŸ’– GIT-NAME-REV(1) πŸ’–

okay bestie, so this is git-name-rev from the Git Manual β€” yes, the actual official one, section 1, we're in the big leagues now ✨


🌸 NAME 🌸

git-name-rev β€” find symbolic names for given revs πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

git name-rev [--tags] [--refs=<pattern>]
               ( --all | --annotate-stdin | <commit-ish>... )

like, that's the whole shape of it. noted. memorized. moving on πŸ’…


✨ DESCRIPTION ✨

so what does it do? It finds symbolic names that are suitable for human digestion πŸ‘€ β€” for revisions given in any format parsable by git rev-parse. Basically it takes your scary hex soup and turns it into something a person can actually read. it's giving translator. it's giving "let me explain him to you". 🫢


πŸ’… OPTIONS πŸ’…

  • --tags β€” do not use branch names, bestie. only tags to name the commits. tags only. periodt πŸŽ€
  • --refs=<pattern> β€” only use refs whose names match a given shell pattern. the pattern can be a branch name, a tag name, or a fully qualified ref name. if given multiple times, use refs whose names match any of the given shell patterns. and use --no-refs to clear any previous ref patterns you gave. 🧹
  • --exclude=<pattern> β€” do not use any ref whose name matches a given shell pattern. the pattern can be one of branch name, tag name or fully qualified ref name. if given multiple times, a ref will be excluded when it matches any of the given patterns. when used together with --refs, a ref will be used as a match only when it matches at least one --refs pattern and does not match any --exclude patterns. use --no-exclude to clear the list of exclude patterns. so it's like a lil bouncer for your refs, iykyk πŸšͺ
  • --all β€” list all commits reachable from all refs. all of them. every last one. 🌈
  • --annotate-stdin β€” transform stdin by substituting all the 40-character SHA-1 hexes (say $hex) with "$hex ($rev_name)". when used with --name-only, substitute with "$rev_name", omitting $hex altogether. lowkey important: this option was called --stdin in older versions of Git. πŸ™ˆ

for example:

$ cat sample.txt

An abbreviated revision 2ae0a9cb82 will not be substituted.
The full name after substitution is 2ae0a9cb8298185a94e5998086f380a355dd8907,
while its tree object is 70d105cc79e63b81cfdcb08a15297c23e60b07ad

$ git name-rev --annotate-stdin <sample.txt

An abbreviated revision 2ae0a9cb82 will not be substituted.
The full name after substitution is 2ae0a9cb8298185a94e5998086f380a355dd8907 (master),
while its tree object is 70d105cc79e63b81cfdcb08a15297c23e60b07ad

$ git name-rev --name-only --annotate-stdin <sample.txt

An abbreviated revision 2ae0a9cb82 will not be substituted.
The full name after substitution is master,
while its tree object is 70d105cc79e63b81cfdcb08a15297c23e60b07ad

look at that. the full hex ate and left the abbreviated one behind, no crumbs 😭

  • --name-only β€” instead of printing both the SHA-1 and the name, print only the name. if given with --tags the usual tag prefix of "tags/" is also omitted from the name, matching the output of git-describe more closely. iconic behavior honestly πŸ‘‘
  • --no-undefined β€” die with error code != 0 when a reference is undefined, instead of printing undefined. so like, it refuses to be vague. it will not say "idk" it will simply explode. πŸ’€
  • --always β€” show uniquely abbreviated commit object as fallback. a lil safety net for when nothing else is naming it. 🫢

πŸ“ EXAMPLES πŸ“

given a commit, find out where it is relative to the local refs. say somebody wrote you about that fantastic commit 33db5f4d9027a10e477ccf054b2c1ab94f74c85a. of course, you look into the commit, but that only tells you what happened, not the context. rude of it, honestly.

enter git name-rev:

% git name-rev 33db5f4d9027a10e477ccf054b2c1ab94f74c85a
33db5f4d9027a10e477ccf054b2c1ab94f74c85a tags/v0.99~940

now you are wiser πŸ’« because you know that it happened 940 revisions before v0.99. the context has been served. slay.

another nice thing you can do is:

% git log | git name-rev --annotate-stdin

literally just pipe your log into it and watch the vibes get labeled. obsessed. πŸ”₯


πŸ‘‘ GIT πŸ‘‘

part of the git(1) suite. one of the family. the nepo baby of the git suite, but like, in a talented way. 🧚


and that's the whole page, bestie! okay so the official footer energy is: Git 2.56.0, dated 2026-09-27 β€” that's the source/version-and-date sign-off, mwah, go name some revs πŸ’œβœ¨

πŸ“¦ where this page comes from