简体中文 ▾ 主题 ▾ 最新版本 ▾ git-name-rev 最后更新于 2.43.0

名称

git-name-rev - 为给定修订版本查找符号名称

概要

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

当引用未定义时,以非零退出码退出,而不是打印 undefined

--always

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

示例

给定一个提交,找出它相对于本地引用的位置。假设某人写信给你说有一个很棒的提交 33db5f4d9027a10e477ccf054b2c1ab94f74c85a。当然,你查看了那个提交,但这只告诉你发生了什么,但没有上下文。

输入 git name-rev

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

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

你还可以做另一件 nice 的事情:

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

GIT

Git[1] 套件的一部分