2013-02-24

Git Tag

Tag(標籤)可以用來標注重要的時間點,例如 v1.0 或 v2.0。

Git 提供兩種標籤:Lightweight 與 Annotated,Lightweight 標籤就只是一個標籤,沒有紀錄其他訊息,而 Annotated 標籤則紀錄了較多資料。

Lightweight 標籤
> git tag v1.0

> git tag
v1.0

> git show v1.0
commit c7e3939502f760a46df336d0acf9470151f81c8c
Author: Neil <cw1057@gmail.com>
Date:   Sun Feb 24 15:17:22 2013 +0800

    'add_b.txt'

diff --git a/b.txt b/b.txt
new file mode 100644
index 0000000..e69de29
Annotated 標籤
> git tag -a v2.0 -m 'v2.0'

> git tag
v1.0
v2.0

> git show v2.0
tag v2.0
Tagger: Neil <cw1057@gmail.com>
Date:   Sun Feb 24 20:06:35 2013 +0800

'v2.0'

commit c7e3939502f760a46df336d0acf9470151f81c8c
Author: Neil <cw1057@gmail.com>
Date:   Sun Feb 24 15:17:22 2013 +0800

    'add_b.txt'

diff --git a/b.txt b/b.txt
new file mode 100644
index 0000000..e69de29
Annotated 標籤比 Lightweight 標籤多紀錄了標籤者、標籤日期與額外的訊息。

Git 標籤也可以事後補標
> git log --pretty=oneline
c7e3939502f760a46df336d0acf9470151f81c8c 'add_b.txt'
852e733537af2277b3c4e7815e7d32f803c94903 'add_a.txt'

> git tag -a v0.5 -m 'v0.5' c7e3939502f760a46df336d0acf9470151f81c8c

> git tag
v0.5
v1.0
v2.0

push 標籤到遠端
git push 預設是不會將標籤送到遠端的,必須明確 push 標籤才行。
> git push origin v1.0
Password for 'https://cw1057@bitbucket.org':
Total 0 (delta 0), reused 0 (delta 0)
remote: bb/acl: cw1057 is allowed. accepted payload.
To https://cw1057@bitbucket.org/cw1057/test.git
 * [new tag]         v1.0 -> v1.0

> git push origin --tags
Password for 'https://cw1057@bitbucket.org':
Counting objects: 2, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 193 bytes, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: bb/acl: cw1057 is allowed. accepted payload.
To https://cw1057@bitbucket.org/cw1057/test.git
 * [new tag]         v0.5 -> v0.5
 * [new tag]         v2.0 -> v2.0
可以用 git push [remote name] [tag name] 來 push 指定的標籤到遠端,也可以用 git push [remote name] --tags 來一次將所有遠端沒有的標籤都 push 到遠端。

回到 Git 學習筆記
---
---
---

沒有留言:

張貼留言