R's Workshop

Git Tag 筆記

紀錄一些比較冷門的 git tag 指令.

Annotated Tags and Lightweight Tags

Git tag 分為兩大類: annotated tag 和 lightweight tag.

Add Tags

Leighweight tag 和 branch 概念類似, 都是一個指向某個 commit object 的 pointer

$ git tag TAG_NAME [COMMIT-ISH]

Annotated tag 和 commit/tree/blob 一樣, 為 git 的基礎物件之一. 除了指向某個 commit 物件外, 也包含了 tagging message 等資訊.

$ git tag -a TAG_NAME [COMMIT-ISH]

要分辨一個 tag 是 annotated 或是 lightweight, 可輸入以下指令. 若有出現 ^{} dereference operator, 就是 annotated tags.

$ git show-ref -d --tags [TAG_NAME]

Delete Tags

$ git tag -d TAG_NAME

Interaction with Remote

和 remote git repos 操作.

Push Tags to Remote

$ git push REMOTE TAG_NAME

Delete Tags on Remote

簡單的刪除命令如下.

$ git push --delete origin TAG_NAME

也可以 push 一個 empty reference 到 remote.

$ git push origin :TAG_NAME

Reference

Git