當前位置:
首頁 > 知識 > Git的標籤

Git的標籤

如果你達到一個重要的階段,並希望永遠記住那個特別的提交快照,你可以使用 git tag 給它打上標籤。

比如說,我們想為我們的 run 項目發布一個"1.0"版本。 我們可以用 git tag -a v1.0 命令給最新一次提交打上(HEAD)"v1.0"的標籤。

-a 選項意為"創建一個帶註解的標籤"。 不用 -a 選項也可以執行的,但它不會記錄這標籤是啥時候打的,誰打的,也不會讓你添加個標籤的註解。 我推薦一直創建帶註解的標籤。

$ git tag -a v1.0

當你執行 git tag -a 命令時,Git 會打開你的編輯器,讓你寫一句標籤註解,就像你給提交寫註解一樣。

現在,注意當我們執行 git log --decorate 時,我們可以看到我們的標籤了:

$ git log --oneline --decorate --graph* 88afe0e (HEAD, tag: v1.0, master) Merge branch "change_site"|
| * d7e7346 (change_site) changed the site* | 14b4dca 新增加一行|/ * 556f0a0 removed test2.txt* 2e082b7 add test2.txt* 048598f add test.txt* 85fc7e7 test comment from runoob.com

如果我們忘了給某個提交打標籤,又將它發布了,我們可以給它追加標籤。

例如,假設我們發布了提交 85fc7e7(上面實例最後一行),但是那時候忘了給它打標籤。 我們現在也可以:

$ git tag -a v0.9 85fc7e7$ git log --oneline --decorate --graph* 88afe0e (HEAD, tag: v1.0, master) Merge branch "change_site"|
| * d7e7346 (change_site) changed the site* | 14b4dca 新增加一行|/ * 556f0a0 removed test2.txt* 2e082b7 add test2.txt* 048598f add test.txt* 85fc7e7 (tag: v0.9) test comment from runoob.com

如果我們要查看所有標籤可以使用以下命令:

$ git tag
v0.9v1.0

指定標籤信息命令:

git tag -a <tagname> -m "run.com標籤"

PGP簽名標籤命令:

git tag -s <tagname> -m "run.com標籤"

Git的標籤

喜歡這篇文章嗎?立刻分享出去讓更多人知道吧!

本站內容充實豐富,博大精深,小編精選每日熱門資訊,隨時更新,點擊「搶先收到最新資訊」瀏覽吧!


請您繼續閱讀更多來自 程序員小新人學習 的精彩文章:

XPath總結
XML的 用途

TAG:程序員小新人學習 |