打標(biāo)簽
Git 可以給歷史中的某一個(gè)提交打上標(biāo)簽畏纲,以示重要扇住。 比
較有代表性的是人們會使用這個(gè)功能來標(biāo)記發(fā)布結(jié)點(diǎn)(v1.0 等等)
列出標(biāo)簽
git tag
列出所有標(biāo)簽
git tag -l 'v1.8*'
列出標(biāo)簽前面字符是v1.8的所有標(biāo)簽
$git tag -l 'v2.9*'
v2.9.0
v2.9.0-rc0
v2.9.0-rc1
v2.9.0-rc2
v2.9.1
v2.9.2
v2.9.3
v2.9.4
v2.9.5
創(chuàng)建標(biāo)簽
默認(rèn)標(biāo)簽創(chuàng)建在最新提交的commit上
- 輕量級標(biāo)簽 特定提交的一個(gè)引用
- 附注標(biāo)簽 是存儲在git庫的一個(gè)完整對象,包括打標(biāo)簽者的姓名盗胀、郵箱艘蹋、創(chuàng)建時(shí)間等(建議創(chuàng)建附注標(biāo)簽)
輕量級標(biāo)簽
# 創(chuàng)建
# 輕量級標(biāo)簽,不需要提供-a票灰、-m女阀、-s等參數(shù),直接提供標(biāo)簽名
$ git tag test_lightweight
附注標(biāo)簽
# 創(chuàng)建
$ git tag -a v1.0 -m 'test tag v1.0'
# -a 添加附注標(biāo)簽
# -m 編寫標(biāo)簽信息
-m 如果沒有提供屑迂,git會運(yùn)行編輯器要求你輸入信息
追加(后期)打標(biāo)簽
# 查看提交紀(jì)錄
$ git log --pretty=oneline
83428cee2f039c2cfd3a2cc93e952c2273c56e6f (HEAD -> master, origin/master, origin/HEAD) add e
a03793cc16833f2347538ddb455e6f273a026d62 add d
c909fd331b2dd74f4a031eb935b3ed4d7655bdf6 (tag: v1.2) add c
現(xiàn)在在add d
上增加標(biāo)簽
$ git tag -a v1.3 a03793cc16833 -m 'add tag'
$ git log --pretty=oneline
83428cee2f039c2cfd3a2cc93e952c2273c56e6f (HEAD -> master, origin/master, origin/HEAD) add e
a03793cc16833f2347538ddb455e6f273a026d62 (tag: v1.3) add d
c909fd331b2dd74f4a031eb935b3ed4d7655bdf6 (tag: v1.2) add c
查看標(biāo)簽
git show tag_name
# 附注標(biāo)簽的 tag show
$git show v1.1
tag v1.1
Tagger: yin <yjd48676@ly.com>
Date: Sat Dec 16 14:14:10 2017 +0800
test tag
commit 439ac73c29a0fe1c10fd975dc48f766e54e20654 (tag: v1.1)
Author: yin <yjd48676@ly.com>
Date: Sat Dec 16 14:13:17 2017 +0800
add b
# 輕量級的 tag show
$git show test_lightweight
commit d81250633475814521e66e78b102a501f3cf2ebe (tag: test_lightweight, tag: show)
Author: yin <yjd48676@ly.com>
Date: Sat Dec 16 14:07:25 2017 +0800
add a
共享標(biāo)簽(推送標(biāo)簽到遠(yuǎn)端服務(wù)器)
默認(rèn)情況下git push
并不會推送標(biāo)簽到遠(yuǎn)端服務(wù)器浸策,在創(chuàng)建完標(biāo)簽后需要顯示的推送標(biāo)簽到服務(wù)器上。
推一個(gè)標(biāo)簽git push origin [tagname]
推所有標(biāo)簽git push origin --tags
# 推一個(gè)標(biāo)簽
$ git push origin v1.3
Counting objects: 1, done.
Writing objects: 100% (1/1), 150 bytes | 150.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To github.com:JinduYin/test_git.git
* [new tag] v1.3 -> v1.3
# 推所有標(biāo)簽 同步本地的所有tag到服務(wù)器
$ git push origin --tags
Counting objects: 2, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 272 bytes | 272.00 KiB/s, done.
Total 2 (delta 0), reused 0 (delta 0)
To github.com:JinduYin/test_git.git
* [new tag] show -> show
* [new tag] test_lightweight -> test_lightweight
* [new tag] v1.1 -> v1.1
* [new tag] v1.2 -> v1.2
獲取指定tag代碼
git checkout tag_name
切換到某個(gè)tag
$ git checkout v1.2
Note: checking out 'v1.2'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at c909fd3... add c
"detached HEAD" 狀態(tài)
如果你想編輯此tag下的代碼,上面的方法就不適用了
需要把tag的快照對應(yīng)的代碼拉取到一個(gè)新分支上
git checkout -b dev v1.2
在tag v1.2處新建分支
$ git checkout -b dev v1.2
Switched to a new branch 'dev'