標籤操作允許為存儲庫中的特定版本提供有意義的名稱。 假設專案中有兩個程式員:maxsu
和minsu
,他們決定標記專案代碼,以便以後可以更容易訪問這些代碼。
創建標籤
使用git tag
命令來標記當前HEAD
指針。在創建標籤時需要提供-a
選項的標籤名稱,並提供帶-m
選項的標籤消息。
$ pwd
/D/worksp/sample
Administrator@MY-PC /D/worksp/sample (master)
$ git tag -a 'Release_1_0' -m 'Tagged basic string operation code' HEAD
如果要標記特定提交,則使用相應的COMMIT ID
而不是HEAD
指針。使用以下命令將標籤推送到遠程存儲庫。
$ git push origin tag Release_1_0
Username for 'http://git.oschina.net': 769728683@qq.com
Password for 'http://769728683@qq.com@git.oschina.net':
Counting objects: 1, done.
Writing objects: 100% (1/1), 177 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To http://git.oschina.net/zaixian/sample.git
* [new tag] Release_1_0 -> Release_1_0
查看標籤
假設開發人員(maxsu
)創建了標籤。 現在,另外一個開發人員(minsu
)就可以使用帶有-l
選項的git tag
命令查看所有可用的標籤。
zaixian@ubuntu:~/git/sample$ pwd
/home/zaixian/git/sample
zaixian@ubuntu:~/git/sample$ git pull
remote: Counting objects: 1, done.
remote: Total 1 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (1/1), done.
From http://git.oschina.net/zaixian/sample
* [new tag] Release_1_0 -> Release_1_0
Already up-to-date.
zaixian@ubuntu:~/git/sample$ git tag -l
Release_1_0
zaixian@ubuntu:~/git/sample$
可使用git show
命令後跟其標籤名來查看有關標籤的更多詳細資訊。
$ git show Release_1_0
tag Release_1_0
Tagger: maxsu <your_email@mail.com>
Date: Mon Jul 10 23:06:04 2017 +0800
Tagged basic string operation code
commit 44ea8e47307b47c9a80b44360e09f973e79312b0
Author: maxsu <your_email@mail.com>
Date: Mon Jul 10 21:09:35 2017 +0800
add new file string.py
diff --git a/src/string.py b/src/string.py
new file mode 100644
index 0000000..42fd1dd
--- /dev/null
+++ b/src/string.py
@@ -0,0 +1,7 @@
+#!/usr/bin/python3
+
+var1 = 'Hello World!'
+var2 = "Python Programming"
+
+print ("var1[0]: ", var1[0])
+print ("var2[1:5]: ", var2[1:5]) # 切片加索引
\ No newline at end of file
Administrator@MY-PC /D/worksp/sample (master)
$
刪除標籤
使用以下命令從本地以及遠程存儲庫中刪除標籤,注意使用 git tag -d
中帶有-d
選項 -
$ git tag
Release_1_0
Administrator@MY-PC /D/worksp/sample (master)
$ git tag -d Release_1_0
Deleted tag 'Release_1_0' (was 600fa78)
Administrator@MY-PC /D/worksp/sample (master)
$ git push origin :Release_1_0
Username for 'http://git.oschina.net': 769728683@qq.com
Password for 'http://769728683@qq.com@git.oschina.net':
To http://git.oschina.net/zaixian/sample.git
- [deleted] Release_1_0
Administrator@MY-PC /D/worksp/sample (master)
$