簡體中文 ▾ 主題 ▾ 最新版本 ▾ 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] 套件的一部分