允許有意義的名稱到一個特定的版本庫中的標簽操作。Sampson 決定標記他們的項目代碼,以便他們以后可以更容易訪問。
## 創建標簽
讓我們標記當前HEAD使用git tag命令。他提供的標記名稱前加上-a選項,使用-m選項,并提供標簽信息。
sampson@CentOS project]$ pwd
/home/sampson/top_repo/project
[sampson@CentOS project]$ git tag -a 'Release_1_0' -m 'Tagged basic string operation code' HEAD
如果想標記特定提交然后使用適當的COMMIT ID,而不是HEAD 指針。 Sampson使用下面的命令推到遠程存儲庫中的標簽。
[sampson@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
## 查看標簽
Sampson 創建標簽。現在,Byron 可以查看所有可用標簽通過使用Git tag命令使用-l選項。
[byron@CentOS src]$ pwd
/home/byron/byron_repo/project/src
[byron@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.
[byron@CentOS src]$ git tag -l
Release_1_0
Byron 使用Git的show命令后跟標記名稱的有關標簽查看更多細節。
[byron@CentOS src]$ git show Release_1_0
上面的命令會產生以下結果。
tag Release_1_0
Tagger: Sampson <sampson@12xue.com>
Date: Wed Sep 11 13:45:54 2015 +0530
Tagged basic string operation code
commit 577647211ed44fe2ae479427a0668a4f12ed71a1
Author: Sampson <sampson@12xue.com>
Date: Wed Sep 11 10:21:20 2015 +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
## 刪除標簽
Sampson使用下面的命令來刪除標記從本地以及遠程倉庫。
[sampson@CentOS project]$ git tag
Release_1_0
[sampson@CentOS project]$ git tag -d Release_1_0
Deleted tag 'Release_1_0' (was 0f81ff4)
# Remove tag from remote repository.
[sampson@CentOS project]$ git push origin :Release_1_0
To gituser@git.server.com:project.git
- [deleted]
Release_1_0