- Git Essentials(Second Edition)
- Ferdinando Santacroce
- 488字
- 2021-07-02 15:27:10
Tags are fixed labels
Tags are labels you can pin to a commit, but unlike branches, they will stay there.
Creating a tag is simple: you only need the git tag command, followed by a tag name; we can create one in the tip commit of bug branch to give it a try; check out the bug branch:
[1] ~/grocery (master) $ git checkout bug Switched to branch 'bug'
Then use the git tag command followed by the funny bugTag name:
[2] ~/grocery (bug) $ git tag bugTag
Let's see what git log says:
[3] ~/grocery (bug) $ git log --oneline --graph --decorate --all * 07b1858 (HEAD -> bug, tag: bugTag) Bug eats all the fruits! | * a8c6219 (melons) Add a watermelon | * ef6c382 (berries) Add a blackberry | * 0e8b5cf (master) Add an orange
|/
* e4a5e7b Add an apple * a57d783 Add a banana to the shopping list
As you can see in the log, now on the tip of the bug branch there is even a tag named bugTag.
If you do a commit in this branch, you will see the bugTag will remain at its place; add a new line to the same old shopping list file:
[4] ~/grocery (bug) $ echo "another bug" >> shoppingList.txt
Perform a commit:
[5] ~/grocery (bug) $ git commit -am "Another bug!" [bug 5d605c6] Another bug! 1 file changed, 1 insertion(+)
Then look at the current situation:
[6] ~/grocery (bug) $ git log --oneline --graph --decorate --all * 5d605c6 (HEAD -> bug) Another bug! * 07b1858 (tag: bugTag) Bug eats all the fruits! | * a8c6219 (melons) Add a watermelon | * ef6c382 (berries) Add a blackberry | * 0e8b5cf (master) Add an orange |/ * e4a5e7b Add an apple * a57d783 Add a banana to the shopping list
That's exactly what we predict.
Tags are useful to give a particular meaning to some particular commits; for instance, as a developer, you maybe want to tag every release of your software: in that case, this is all you need to know to do that job.
Even tags are references, and they are stored, as branches, as simple text files in the tags subfolder within the .git folder; take a look under the .git/refs/tags folder, you will see a bugTag file; look at the content:
[7] ~/grocery (bug) $ cat .git/refs/tags/bugTag 07b18581801f9c2c08c25cad3b43aeee7420ffdd
As you maybe have already predicted, it contains the hash of the commit it refers to.
To delete a tag, you have to simply append the -d option: git tag -d <tag name>.
As you can't move a tag, if you need to move it you have to delete the previous tag and then create a new one with the same name that points to the commit you want; you can create a tag that points a commit wherever you want, appending the hash of the commit as an argument, for example, git tag myTag 07b1858.
- Hands-On Data Structures and Algorithms with Rust
- 數(shù)據(jù)可視化:從小白到數(shù)據(jù)工程師的成長(zhǎng)之路
- 大數(shù)據(jù)算法
- 達(dá)夢(mèng)數(shù)據(jù)庫(kù)性能優(yōu)化
- Ceph源碼分析
- 基于Apache CXF構(gòu)建SOA應(yīng)用
- “互聯(lián)網(wǎng)+”時(shí)代立體化計(jì)算機(jī)組
- ZeroMQ
- 大數(shù)據(jù)技術(shù)入門
- 大數(shù)據(jù)架構(gòu)商業(yè)之路:從業(yè)務(wù)需求到技術(shù)方案
- 一本書講透Elasticsearch:原理、進(jìn)階與工程實(shí)踐
- Expert Python Programming(Third Edition)
- Spring MVC Beginner’s Guide
- Oracle 11g+ASP.NET數(shù)據(jù)庫(kù)系統(tǒng)開(kāi)發(fā)案例教程
- ECharts數(shù)據(jù)可視化:入門、實(shí)戰(zhàn)與進(jìn)階