{
    "mode": "man",
    "parameter": "git-name-rev",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/git-name-rev/1/json",
    "generated": "2026-09-05T11:25:25Z",
    "synopsis": "git name-rev [--tags] [--refs=<pattern>]\n( --all | --annotate-stdin | <commit-ish>... )",
    "sections": {
        "NAME": {
            "content": "git-name-rev - Find symbolic names for given revs\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "git name-rev [--tags] [--refs=<pattern>]\n( --all | --annotate-stdin | <commit-ish>... )\n\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Finds symbolic names suitable for human digestion for revisions given in any format parsable\nby git rev-parse.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "",
            "subsections": [
                {
                    "name": "--tags",
                    "content": "Do not use branch names, but only tags to name the commits\n\n--refs=<pattern>\nOnly use refs whose names match a given shell pattern. The pattern can be a branch name,\na tag name, or a fully qualified ref name. If given multiple times, use refs whose names\nmatch any of the given shell patterns. Use --no-refs to clear any previous ref patterns\ngiven.\n\n--exclude=<pattern>\nDo not use any ref whose name matches a given shell pattern. The pattern can be one of\nbranch name, tag name or fully qualified ref name. If given multiple times, a ref will be\nexcluded when it matches any of the given patterns. When used together with --refs, a ref\nwill be used as a match only when it matches at least one --refs pattern and does not\nmatch any --exclude patterns. Use --no-exclude to clear the list of exclude patterns.\n",
                    "long": "--tags"
                },
                {
                    "name": "--all",
                    "content": "List all commits reachable from all refs\n",
                    "long": "--all"
                },
                {
                    "name": "--annotate-stdin",
                    "content": "Transform stdin by substituting all the 40-character SHA-1 hexes (say $hex) with \"$hex\n($revname)\". When used with --name-only, substitute with \"$revname\", omitting $hex\naltogether. This option was called --stdin in older versions of Git.\n\nFor example:\n\n$ cat sample.txt\n\nAn abbreviated revision 2ae0a9cb82 will not be substituted.\nThe full name after substitution is 2ae0a9cb8298185a94e5998086f380a355dd8907,\nwhile its tree object is 70d105cc79e63b81cfdcb08a15297c23e60b07ad\n\n$ git name-rev --annotate-stdin <sample.txt\n\nAn abbreviated revision 2ae0a9cb82 will not be substituted.\nThe full name after substitution is 2ae0a9cb8298185a94e5998086f380a355dd8907 (master),\nwhile its tree object is 70d105cc79e63b81cfdcb08a15297c23e60b07ad\n\n$ git name-rev --name-only --annotate-stdin <sample.txt\n\nAn abbreviated revision 2ae0a9cb82 will not be substituted.\nThe full name after substitution is master,\nwhile its tree object is 70d105cc79e63b81cfdcb08a15297c23e60b07ad\n\n",
                    "long": "--annotate-stdin"
                },
                {
                    "name": "--name-only",
                    "content": "Instead of printing both the SHA-1 and the name, print only the name. If given with\n--tags the usual tag prefix of \"tags/\" is also omitted from the name, matching the output\nof git-describe more closely.\n",
                    "long": "--name-only"
                },
                {
                    "name": "--no-undefined",
                    "content": "Die with error code != 0 when a reference is undefined, instead of printing undefined.\n",
                    "long": "--no-undefined"
                },
                {
                    "name": "--always",
                    "content": "Show uniquely abbreviated commit object as fallback.\n",
                    "long": "--always"
                }
            ]
        },
        "EXAMPLES": {
            "content": "Given a commit, find out where it is relative to the local refs. Say somebody wrote you about\nthat fantastic commit 33db5f4d9027a10e477ccf054b2c1ab94f74c85a. Of course, you look into the\ncommit, but that only tells you what happened, but not the context.\n\nEnter git name-rev:\n\n% git name-rev 33db5f4d9027a10e477ccf054b2c1ab94f74c85a\n33db5f4d9027a10e477ccf054b2c1ab94f74c85a tags/v0.99~940\n\n\nNow you are wiser, because you know that it happened 940 revisions before v0.99.\n\nAnother nice thing you can do is:\n\n% git log | git name-rev --annotate-stdin\n\n",
            "subsections": []
        },
        "GIT": {
            "content": "Part of the git(1) suite\n\nGit 2.43.0                                   07/02/2025                              GIT-NAME-REV(1)",
            "subsections": []
        }
    },
    "summary": "git-name-rev - Find symbolic names for given revs",
    "flags": [
        {
            "flag": "",
            "long": "--tags",
            "arg": null,
            "description": "Do not use branch names, but only tags to name the commits --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. Use --no-refs to clear any previous ref patterns given. --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."
        },
        {
            "flag": "",
            "long": "--all",
            "arg": null,
            "description": "List all commits reachable from all refs"
        },
        {
            "flag": "",
            "long": "--annotate-stdin",
            "arg": null,
            "description": "Transform stdin by substituting all the 40-character SHA-1 hexes (say $hex) with \"$hex ($revname)\". When used with --name-only, substitute with \"$revname\", omitting $hex altogether. 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"
        },
        {
            "flag": "",
            "long": "--name-only",
            "arg": null,
            "description": "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."
        },
        {
            "flag": "",
            "long": "--no-undefined",
            "arg": null,
            "description": "Die with error code != 0 when a reference is undefined, instead of printing undefined."
        },
        {
            "flag": "",
            "long": "--always",
            "arg": null,
            "description": "Show uniquely abbreviated commit object as fallback."
        }
    ],
    "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, but not the context.",
        "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.",
        "Another nice thing you can do is:",
        "% git log | git name-rev --annotate-stdin"
    ],
    "see_also": [],
    "tldr": {
        "source": "official",
        "description": "Describe a commit using existing ref names.",
        "examples": [
            {
                "description": "Show the name for `HEAD`",
                "command": "git name-rev HEAD"
            },
            {
                "description": "Show only the name",
                "command": "git name-rev --name-only HEAD"
            },
            {
                "description": "Enumerate all matching ref names",
                "command": "git name-rev --all"
            },
            {
                "description": "Use only tags to name the commit",
                "command": "git name-rev --tags HEAD"
            },
            {
                "description": "Exit with a non-zero status code instead of printing `undefined` for unknown commits",
                "command": "git name-rev --no-undefined {{commit-ish}}"
            },
            {
                "description": "Show names for multiple commits",
                "command": "git name-rev HEAD~1 HEAD~2 main"
            },
            {
                "description": "Restrict names to branch refs",
                "command": "git name-rev --refs refs/heads/ {{commit-ish}}"
            },
            {
                "description": "Read commit IDs from `stdin`",
                "command": "echo \"{{commit-ish}}\" | git name-rev --annotate-stdin"
            }
        ]
    }
}