簡體中文 ▾ 主題 ▾ 最新版本 ▾ 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

當引用未定義時,以非 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] 套件的一部分

scroll-to-top