Skip to content

git-name-rev

为给定的修订查找符号名称。

概要

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

描述

为以 'git rev-parse' 可解析的任何格式给出的修订查找适合人类阅读的符号名称。

选项

--tags

:不使用分支名称,仅使用标签来命名提交。

--refs=<pattern>

:仅使用名称与给定 shell 模式匹配的引用。模式可以是分支名、标签名或完全限定引用名。如果多次给出,则使用名称与任何给定 shell 模式匹配的引用。使用 --no-refs 可清除之前给出的引用模式。

--exclude=<pattern>

:不使用名称与给定 shell 模式匹配的任何引用。模式可以是分支名、标签名或完全限定引用名之一。如果多次给出,当引用匹配任何给定模式时将被排除。与 --refs 一起使用时,引用仅在匹配至少一个 --refs 模式且不匹配任何 --exclude 模式时才被使用。使用 --no-exclude 可清除排除模式列表。

--all

:列出从所有引用可达的所有提交。

--annotate-stdin

:通过将所有 40 字符的 SHA-1 十六进制(如 $hex)替换为 "$hex ($rev_name)" 来转换标准输入。与 --name-only 一起使用时,替换为 "$rev_name",完全省略 $hex。此选项在旧版本的 Git 中称为 --stdin。 例如:

$ 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

--name-only

:只打印名称而不是同时打印 SHA-1 和名称。如果与 --tags 一起使用,通常的 "tags/" 标签前缀也会从名称中省略,更接近 git-describe 的输出。

--no-undefined

:当引用未定义时以错误代码 != 0 退出,而不是打印 undefined

--always

:显示唯一缩写的提交对象作为回退。

示例

给定一个提交,找出它相对于本地引用的位置。假设有人向您提到了那个精彩的提交 33db5f4d9027a10e477ccf054b2c1ab94f74c85a。当然,您查看了该提交,但这只告诉您发生了什么,而不是上下文。

使用 'git name-rev':

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

现在您更明智了,因为您知道它发生在 v0.99 之前 940 个修订。

另一个您可以做的好事情是:

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

Git

git(1) 套件的一部分

基于 CC BY-NC-SA 3.0 许可发布