2013-03-29 60 views
4

我做獲取簽出修訂版的git標籤?

$ git tag 

current 
tag_example_to_test_task 

$ git checkout tag_example_to_test_task 

... 

HEAD is now at 75fdde3... commit comment text example 

$ git name-rev --name-only --tags HEAD 

current 

$ git describe --exact-match --tags 

current 

我需要結束執行順序有一些像這樣的命令:

$ git "some command here" 

tag_example_to_test_task 

如何做到這一點?如何獲取當前簽出標籤的標籤名稱?

+0

要列出所有標籤嗎? git標籤-l –

回答

3

我覺得

git log -n 1 --pretty=format:'%d' 

應該做的伎倆。

但是,它會顯示您當前版本所有分支和標籤的名稱。我不認爲有可能只獲得用於檢查修訂的單個標籤。

0

如果您需要當前版本的詳細信息,請使用git describe。它會告訴你最後一個標籤和提交後的提交數量。人類可讀,真的不適合程序使用。

1

要找到什麼讓你當前的提交,你可以使用

git reflog | sed q 

要尋找您的最後結帳:

git reflog | sed '/ checkout: /! d; q' 

這將讓你像

b836444 [email protected]{7}: checkout: moving from AMFD to testing 

表示自做git checkout testing以來已添加了7次提交。

0

這隻輸出最新落實的標籤。

# git log | head -1 
commit 507e0647efd7e49aee53b14da970a7c2bf24555b 
0

這應該做的伎倆:

git tag --points-at=$(git rev-parse HEAD) 

git rev-parse HEAD將獲得當前HEAD的SHA256。如果這個提交恰好被標記,這將被回覆。如果當前HEAD未被標記,則結果爲空。