git 列出標簽
Tagging lets developers mark important checkpoints in the course of their projects' development. For instance, software release versions can be tagged. (Ex: v1.3.2) It essentially allows you to give a commit a special name(tag).
通過標記,開發人員可以在項目開發過程中標記重要的檢查點。 例如,可以標記軟件發行版本。 (例如:v1.3.2)從本質上講,它可以使提交具有特殊的名稱(標記)。
To view all the created tags in alphabetical order:
要按字母順序查看所有創建的標簽:
git tag
To get more information on a tag:
要獲取有關標簽的更多信息:
git show v1.4
There are two types of tags:
標簽有兩種類型:
Annotated
帶注解
git tag -a v1.2 -m "my version 1.4"
Lightweight
輕巧的
git tag v1.2
They differ in the way that they are stored.These create tags on your current commit.
它們的存儲方式不同。這些在當前提交時創建標記。
Incase, you’d like to tag a previous commit specify the commit ID you’d like to tag:
如果要標記上一個提交,請指定要標記的提交ID:
git tag -a v1.2 9fceb02
The tags names may be used instead of commit IDs while checking out and pushing commits to a remote repo.
在簽出并將推送推送到遠程存儲庫時,可以使用標簽名稱代替提交ID。
更多信息: (More Information:)
Git documentation: Documentation
Git文檔: 文檔
Git Tagging Chapter: Book
Git標簽章節: 書
You can list all available tags in a project with the git tag
command (nate that they will appear in alphabetical order):
您可以使用git tag
命令列出項目中所有可用的標簽(它們將以字母順序顯示):
$ git tag
v1.0
v2.0
v3.0
This way of listing tags is great for small projects, but greater projects can have hundreds of tags, so you may need to filter them when searching for an important point in the history. You can find tags containing specific characters adding an -l
to the git tag
command:
這種列出標簽的方式非常適合小型項目,但是較大的項目可以包含數百個標簽,因此在搜索歷史中的重要點時可能需要過濾它們。 您可以找到包含特定字符的git tag
,在git tag
命令中添加-l
:
$ git tag -l "v2.0*"
v2.0.1
v2.0.2
v2.0.3
v2.0.4
建立標簽 (Create a tag)
You can create two type of tags: annotated and lightweight. They first ones are compete objects in GIT database: they are checksummed, requiere a message (like commits) and store other important data such as name, email and date. On the other hand, lightweight tags don require a mesage or store other data, working just as a pointer to a specific point in the project.
您可以創建兩種類型的標簽:帶注釋的標簽和輕量標簽。 它們中的第一個是GIT數據庫中的競爭對象:對它們進行校驗和,要求一條消息(例如提交)并存儲其他重要數據,例如名稱,電子郵件和日期。 另一方面,輕量級標簽不需要消息或存儲其他數據,就像指向項目中特定點的指針一樣。
創建帶注釋的標簽 (Create an annotated tag)
To create an anotated tag, add -a tagname -m "tag message"
to the git tag
command:
要創建帶注釋的標簽,請在git tag
命令中添加-a tagname -m "tag message"
:
$ git tag -a v4.0 -m "release version 4.0"
$ git tag
v1.0
v2.0
v3.0
v4.0
As you can see, the -a
specifies that you are creating an annotated tag, after comes the tag name and finally, the -m
followed by the tag message to store in the Git database.
如您所見, -a
指定您要創建帶注釋的標簽,標簽名稱后面是-a
,最后是-m
后跟標簽消息以存儲在Git數據庫中。
創建一個輕量級標簽 (Create a lightweight tag)
Lightweight tags contain only the commit checksum (no other information is stored). To create one, just run the git tag
command without any other options (the -lw characters at the end of the name are used to indicate lightweight tags, but you can mark them as you like):
輕量級標簽僅包含提交校驗和(不存儲其他信息)。 要創建一個,只需運行git tag
命令,不帶任何其他選項(名稱末尾的-lw字符用于表示輕量級標簽,但您可以根據需要對其進行標記):
$ git tag v4.1-lw
$ git tag
v1.0
v2.0
v3.0
v4.0
v4.1-lw
This time you didn’t specify a message or other relevant data, so the tag contains only the refered commit’s checksum.
這次您沒有指定消息或其他相關數據,因此標簽僅包含引用的提交的校驗和。
查看標簽的數據 (View tag’s data)
You can run the git show
command to view the data stored in a tag. In the case of annotated tags, you’ll see the tag data and the commit data:
您可以運行git show
命令來查看存儲在標簽中的數據。 對于帶注釋的標簽,您將看到標簽數據和提交數據:
$ git show v4.0
tag v4.0
Tagger: John Cash <john@cash.com>
Date: Mon Sat 28 15:00:25 2017 -0700release version 4.0commit da43a5fss745av88d47839247990022a98419093
Author: John Cash <john@cash.com>
Date: Fri Feb 20 20:30:05 2015 -0700finished details
If the tag you are watching is a lightweight tag, you’ll only see the refered commit data:
如果您正在查看的標簽是輕量級標簽,則您只會看到引用的提交數據:
$ git show v1.4-lw
commit da43a5f7389adcb9201ab0a289c389ed022a910b
Author: John Cash <john@cash.com>
Date: Fri Feb 20 20:30:05 2015 -0700finished details
標記舊提交 (Tagging old commits)
You can also tag past commits using the git tag commit. In order to do this, you’ll need to specify the commit’s checksum (or at least a part of it) in the command’s line.
您還可以使用git標簽commit標記過去的提交。 為此,您需要在命令行中指定提交的校驗和(或至少校驗和的一部分)。
First, run git log to find out the required commit’s checksum:
首先,運行git log找出所需提交的校驗和:
$ git log --pretty=oneline
ac2998acf289102dba00823821bee04276aad9ca added products section
d09034bdea0097726fd8383c0393faa0072829a7 refactorization
a029ac120245ab012bed1ca771349eb9cca01c0b modified styles
da43a5f7389adcb9201ab0a289c389ed022a910b finished details
0adb03ca013901c1e02174924486a08cea9293a2 small fix in search textarea styles
When you have the checksum needed, add it at the end of the tag creation line:
擁有所需的校驗和后,將其添加到標簽創建行的末尾:
$ git tag -a v3.5 a029ac
You’ll see the tag was correctly added running git tag
:
您會看到標簽已正確添加,并運行git tag
:
$ git tag
v1.0
v2.0
v3.0
v3.5
v4.0
v4.1-lw
推送標簽 (Push tags)
Git does’t push tags by default when you run the git push command. So, to succesfully push a tag to a server you’ll have to git push origin
command:
默認情況下,當您運行git push命令時,Git不會推送標簽。 因此,要成功將標簽推送到服務器,您必須使用git push origin
命令:
$ git push origin v4.0
Counting objects: 14, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (16/16), done.
Writing objects: 100% (18/18), 3.15 KiB | 0 bytes/s, done.
Total 18 (delta 4), reused 0 (delta 0)
To git@github.com:jcash/gitmanual.git* [new tag] v4.0 -> v4.0
You can also use the --tags
option to add multiple tags at once with the git push origin
command:
您還可以使用--tags
選項通過git push origin
命令一次添加多個標簽:
$ git push origin --tags
Counting objects: 1, done.
Writing objects: 100% (1/1), 160 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To git@github.com:jcash/gitmanual.git* [new tag] v4.0 -> v4.0* [new tag] v4.1-lw -> v4.1-lw
簽出標簽 (Checking out Tags)
You can use git checkout
to checkout to a tag like you would normally do. But you need to keep in mind that this would result a detached HEAD state.
您可以git checkout
使用git checkout
簽出到標簽。 但是您需要記住,這將導致HEAD狀態分離 。
$ git checkout v0.0.3
Note: checking out 'v0.0.3'.You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
刪除標簽 (Deleting a Tag)
You may find a situation were you want to delete a certain tag. There’s a very useful command for this situations:
如果您要刪除某個標簽,可能會發現一種情況。 對于這種情況有一個非常有用的命令:
$ git tag --delete v0.0.2
$ git tag
v0.0.1
v0.0.3
v0.0.4
更多信息 (More Information)
Git Pro - Tagging Basics
Git Pro-標記基礎
Git Pro - Documentation
Git Pro-文檔
Git HowTo
Git HowTo
Git tip: Tags
Git提示:標簽
Creating a tag
創建標簽
資料來源 (Sources)
Git documentation: tags
Git文檔: 標簽
翻譯自: https://www.freecodecamp.org/news/git-tag-explained-how-to-add-remove/
git 列出標簽