标签类似于快照功能,我们可以给版本库打一个标签,记录某个时刻库的状态。我们可以随时恢复到该状态。
在master分支上打个标签
[[email protected] yunweigit-]# git checkout master 切换分支
Switched to branch 'master'
[[email protected] yunweigit-]# git branch 查看在那个分支
dev
guozhen
* master
[[email protected] yunweigit-]# git tag v1.0 打标签
[[email protected] yunweigit-]# git tag 查看版本
v1.0
[[email protected] yunweigit-]# git show v1.0 查看标签信息
commit 87109796cee235ab5f26a35584eec32e3f8bf382
Author: azhen <[email protected]>
Date: Sat Sep 17 18:21:17 2016 +0800
add nue 3.txt
diff --git a/3.txt b/3.txt
new file mode 100644
index 0000000..2e307cd
--- /dev/null
+++ b/3.txt
@@ -0,0 +1,5 @@
+adas
+da
+sd
+as
+dsdasdasd
删掉一个标签
[[email protected] yunweigit-]# git tag
v1.0
v2.0
[[email protected] yunweigit-]# git tag -d v2.0
Deleted tag 'v2.0' (was 8710979)
[[email protected] yunweigit-]# git tag
v1.0
tag是针对commit来打标签的,所以可以针对历史的commit来打tag
[[email protected] yunweigit-]# git log --pretty=oneline --abbrev-commit 查看历史
8710979 add nue 3.txt
8b6db89 sdasda 999.txt
e86c86d add 66a 999.txt
6f2009e add a 999.txt
bedacb5 add lanmp.sh
6f67d31 sss yunweibanyungong.txt
97f8da5 change yunweibanyungong.txt
c6fb04a add yunweibanyungong.txt
[[email protected] yunweigit-]# git tag v1 bedacb5 打标签
[[email protected] yunweigit-]# git tag 查看标签
v1
v1.0
[[email protected] yunweigit-]# git show v1 查看标签信息
commit bedacb5ee705ec9c692dc5d25bc6df7c98b29a04
Author: azhen <[email protected]>
Date: Sat Sep 17 16:45:00 2016 +0800
add lanmp.sh
diff --git a/lanmp.sh b/lanmp.sh
new file mode 100644
index 0000000..31811cf
--- /dev/null
+++ b/lanmp.sh
@@ -0,0 +1,3 @@
+#ddddd!/bin/bash
+## written by aming.
+## 2015-06-24.
对标签进行描述
[[email protected] yunweigit-]# git tag -a v11 -m "ceshi" 6f67d31
[[email protected] yunweigit-]# git tag
v1
v1.0
v11
[[email protected] yunweigit-]# git show v11
tag v11
Tagger: azhen <[email protected]>
Date: Sat Sep 17 20:03:33 2016 +0800
ceshi
commit 6f67d3157db78ecb2bdc661301e64de65eb58557
Author: azhen <[email protected]>
Date: Sat Sep 17 16:11:55 2016 +0800
sss yunweibanyungong.txt
diff --git a/yunweibanyungong.txt b/yunweibanyungong.txt
index 38d526d..6a064cb 100644
--- a/yunweibanyungong.txt
+++ b/yunweibanyungong.txt
@@ -1,2 +1,2 @@
90root
-www.centoscn.cn
+wsasasdasww.centoscn.cn
推送本地标签到远程上
[[email protected] yunweigit-]# git tag
v1
v1.0
v11
[[email protected] yunweigit-]# git push origin v11
Counting objects: 1, done.
Writing objects: 100% (1/1), 150 bytes, done.
Total 1 (delta 0), reused 0 (delta 0)
To [email protected]:guozhenshijia/yunweigit-.git
* [new tag] v11 -> v11
查看有没有推送成功

推送所有标签
[[email protected] yunweigit-]# git push --tag origin
Total 0 (delta 0), reused 0 (delta 0)
To [email protected]:guozhenshijia/yunweigit-.git
* [new tag] v1 -> v1
* [new tag] v1.0 -> v1.0

删除本地标签和远程标签
[[email protected] yunweigit-]# git tag
v1
v1.0
v11
[[email protected] yunweigit-]# git tag v1 -d
Deleted tag 'v1' (was bedacb5)
[[email protected] yunweigit-]# git tag
v1.0
v11
[[email protected] yunweigit-]# git push origin :refs/tags/v1
To [email protected]:guozhenshijia/yunweigit-.git
- [deleted] v1
查看v1版本有没有删掉
