← 返回命令列表

Linux command

git-name-rev 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Find symbolic name for commit

git name-rev [commit]

Name multiple commits

git name-rev [commit1] [commit2]

Annotate commit hashes from stdin

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

Only use tags to name a commit

git name-rev --tags [commit]

Exclude refs matching a pattern

git name-rev --exclude="refs/tags/*" [commit]

Name all reachable commits from all refs

git name-rev --all

说明

git name-rev finds symbolic names for given commit hashes, making them more human-readable. It shows the nearest ref (branch or tag) that can describe each commit, along with the number of commits from that ref (e.g., "main~3" means three commits before main). The `--annotate-stdin` option allows processing commit hashes from pipelines, enabling annotation of `git log` output or other commands that produce commit IDs. Filter options like `--tags` or `--refs` restrict which references are used for naming.

参数

--annotate-stdin
Transform stdin by substituting commit hashes with their symbolic names. Replaces deprecated --stdin.
--tags
Only use tags to name the commits.
--refs _pattern_
Only use refs whose names match a given shell pattern.
--exclude _pattern_
Do not use any ref whose name matches a given shell pattern.
--all
List all commits reachable from all refs.
--name-only
Print only the symbolic name, not the SHA-1.
--no-undefined
Exit with error when a reference is undefined instead of printing "undefined".
--always
Show uniquely abbreviated commit object as fallback when no name is found.

FAQ

What is the git-name-rev command used for?

git name-rev finds symbolic names for given commit hashes, making them more human-readable. It shows the nearest ref (branch or tag) that can describe each commit, along with the number of commits from that ref (e.g., "main~3" means three commits before main). The `--annotate-stdin` option allows processing commit hashes from pipelines, enabling annotation of `git log` output or other commands that produce commit IDs. Filter options like `--tags` or `--refs` restrict which references are used for naming.

How do I run a basic git-name-rev example?

Run `git name-rev [commit]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --annotate-stdin do in git-name-rev?

Transform stdin by substituting commit hashes with their symbolic names. Replaces deprecated --stdin.