Git 学习笔记(标签篇)

创建标签

git tag <tagname> commit id

省略 commit id 表示在当前分支的最新一次 commit 上打标签。创建带有说明的标签,用 -a 指定标签名,-m 指定说明文字,例如:

git tag -a <tagname> -m "tagmessage" commit id

效果如下所示:

$ git log
commit 196661aeb9309094f94a9f2daa37bd425964a733
Author: SoaringFree twofly0313@gmail.com
Date: Sat Dec 3 11:44:08 2016 +0800
Add I'am xxx
commit 77391b35c42d4feb3d69e0fa13595dcce836e524
Author: anyang xautanyang@163.com
Date: Sat Dec 3 11:00:45 2016 +0800
Add git push
commit b9df4072f8fbe352b38218f0aaf7508f48ceed19
Author: 安洋 1595949666@qq.com
Date: Sat Dec 3 10:43:15 2016 +0800
Initial commit
$ git tag V1.0
$ git show V1.0
commit 196661aeb9309094f94a9f2daa37bd425964a733
Author: SoaringFree twofly0313@gmail.com
Date: Sat Dec 3 11:44:08 2016 +0800
Add I'am xxx
diff --git a/README.md b/README.md
index 4237e04..f6e00ca 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,5 @@
# LearnGit
Notes of Git learning
git push -u origin master

+I'm Fujingfei
$ git tag V2.0 77391b35c42
$ git show V2.0
commit 77391b35c42d4feb3d69e0fa13595dcce836e524
Author: anyang xautanyang@163.com
Date: Sat Dec 3 11:00:45 2016 +0800
Add git push
diff --git a/README.md b/README.md
index 22238ef..4237e04 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,3 @@
# LearnGit
Notes of Git learning
+git push -u origin master
$ git tag -a V3.0 -m "tagmessage" b9df4072f8fbe352b
$ git show V3.0
tag V3.0
Tagger: anyang xautanyang@163.com
Date: Sun Dec 4 20:56:49 2016 +0800
tagmessage
commit b9df4072f8fbe352b38218f0aaf7508f48ceed19
Author: 安洋 1595949666@qq.com
Date: Sat Dec 3 10:43:15 2016 +0800
Initial commit
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..22238ef
--- /dev/null
+++ b/README.md
@@ -0,0 +1,2 @@
+# LearnGit
+Notes of Git learning

查看所有标签信息

git tag

效果如下所示:

$ git tag
V1.0
V2.0
V3.0

查看具体标签信息

git show <tagname>

效果如下所示:

$ git show V3.0
tag V3.0
Tagger: anyang xautanyang@163.com
Date: Sun Dec 4 20:56:49 2016 +0800
tagmessage
commit b9df4072f8fbe352b38218f0aaf7508f48ceed19
Author: 安洋 1595949666@qq.com
Date: Sat Dec 3 10:43:15 2016 +0800
Initial commit
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..22238ef
--- /dev/null
+++ b/README.md
@@ -0,0 +1,2 @@
+# LearnGit
+Notes of Git learning

删除本地标签

git tag -d <tagname>

效果如下所示:

$ git tag -d V2.0
Deleted tag 'V2.0' (was 77391b3)
$ git tag
V1.0
V3.0

推送某个标签到远程仓库

git push origin <tagname>

效果如下所示:

$ git push origin V1.0
Total 0 (delta 0), reused 0 (delta 0)
To git@github.com:anyangxaut/LearnGit.git
* [new tag] V1.0 -> V1.0

推送全部尚未推送到远程仓库的本地标签

git push origin --tags

效果如下所示:

$ git push origin --tags
Counting objects: 1, done.
Writing objects: 100% (1/1), 155 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To git@github.com:anyangxaut/LearnGit.git
* [new tag] V1.0 -> V1.0
* [new tag] V3.0 -> V3.0

删除远程标签

git push origin --delete <tagname>

效果如下所示:

$ git push origin --delete V1.0
To git@github.com:anyangxaut/LearnGit.git

  • [deleted] V1.0

相关资料:

  1. Git 官网
  2. Git 官方文档
  3. [廖雪峰的 Git 教程](http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8
    067c8c017b000)
  4. Git 常用命令查询文档
  5. Git 在线学习网址
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • GIT分布式版本控制系统最佳实践 这篇文章来自于老男孩教育高级架构师班12期的徐亮偉同学。 首先感谢老男孩架构师班...
    meng_philip123阅读 3,471评论 4 36
  • 1. 安装 Github 查看是否安装git: $ git config --global user.name "...
    Albert_Sun阅读 13,701评论 9 163
  • 写在前面 在团队做过软件开发的,版本控制必是不可或缺的一项。目前,版本控制主要分为集中式版本控制系统和分布式版本控...
    Jack_lin阅读 9,945评论 45 434
  • 如果说 15 年你还没有将 DevOps 真正应用起来,16 年再不实践也未免太落伍了。国内 ITOM 领军企业 ...
    OneAPM阅读 730评论 0 10
  • chapter1 薄荷味的阿拉伯水烟 连着喝了十来天的红豆汤,绯翠觉得自己开始瘦了。原来肿胀的手指开始骨节...
    hello胖达阅读 157评论 0 0