Git 标签操作
标签操作允许在代码库中为特定版本添加有意义的名称。假设Tom和Jerry决定为他们的项目代码打上标签,以便以后可以轻松访问。
创建标签
让我们使用 git tag 命令为当前的HEAD打上标签。Tom使用-a选项提供一个标签名称,并使用-m选项提供一个标签消息。
tom@CentOS project]pwd
/home/tom/top_repo/project
[tom@CentOS project] git tag -a 'Release_1_0' -m 'Tagged basic string operation code' HEAD
如果要为特定的提交打标签,则使用适当的COMMIT ID而不是HEAD指针。Tom使用以下命令将标签推送到远程仓库中。
[tom@CentOS project]$ git push origin tag Release_1_0
以上命令将产生以下结果 −
Counting objects: 1, done.
Writing objects: 100% (1/1), 183 bytes, done.
Total 1 (delta 0), reused 0 (delta 0)
To gituser@git.server.com:project.git
* [new tag]
Release_1_0 −> Release_1_0
查看标签
Tom创建了标签。现在,Jerry可以使用Git tag命令和-l选项查看所有可用的标签。
[jerry@CentOS src]pwd
/home/jerry/jerry_repo/project/src
[jerry@CentOS src] git pull
remote: Counting objects: 1, done.
remote: Total 1 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (1/1), done.
From git.server.com:project
* [new tag]
Release_1_0 −> Release_1_0
Current branch master is up to date.
[jerry@CentOS src]$ git tag -l
Release_1_0
Jerry使用Git show命令,后跟标签名称来查看有关标签的更多详细信息。
[jerry@CentOS src]$ git show Release_1_0
上述命令将产生以下结果−
tag Release_1_0
Tagger: Tom Cat <tom@tutorialspoint.com>
Date: Wed Sep 11 13:45:54 2013 +0530
Tagged basic string operation code
commit 577647211ed44fe2ae479427a0668a4f12ed71a1
Author: Tom Cat <tom@tutorialspoint.com>
Date: Wed Sep 11 10:21:20 2013 +0530
Removed executable binary
diff --git a/src/string_operations b/src/string_operations
deleted file mode 100755
index 654004b..0000000
Binary files a/src/string_operations and /dev/null differ
删除标签
Tom使用以下命令从本地和远程存储库中删除标签。
[tom@CentOS project]git tag
Release_1_0
[tom@CentOS project] git tag -d Release_1_0
Deleted tag 'Release_1_0' (was 0f81ff4)
# Remove tag from remote repository.
[tom@CentOS project]$ git push origin :Release_1_0
To gituser@git.server.com:project.git
- [deleted]
Release_1_0