Git
English ▾ 主題 ▾ 最新版本 ▾ 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=<模式>

僅使用名稱符合給定 shell 模式的 refs。模式可以是分支名稱、標籤名稱或完整 refs 名稱。如果多次給定,則使用名稱符合任何給定 shell 模式的 refs。使用 --no-refs 來清除先前給定的任何 ref 模式。

--exclude=<模式>

不要使用名稱符合給定 shell 模式的任何 ref。模式可以是分支名稱、標籤名稱或完整 refs 名稱。如果多次給定,當 ref 符合任何給定模式時,將排除該 ref。與 --refs 一起使用時,ref 僅在符合至少一個 --refs 模式且不符合任何 --exclude 模式時才作為匹配項使用。使用 --no-exclude 來清除排除模式清單。

--all

列出從所有 refs 可到達的所有提交

--annotate-stdin

通過將所有 40 個字元的 SHA-1 十六進制(例如 $hex)替換為 "$hex ($rev_name)" 來轉換 stdin。當與 --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

顯示唯一縮寫的提交物件作為後備。

範例

給定一個提交,找出它相對於本地 refs 的位置。假設有人告訴您有關該出色的提交 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