博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
git 列出标签_Git标签介绍:如何在Git中列出,创建,删除和显示标签
阅读量:2520 次
发布时间:2019-05-11

本文共 6643 字,大约阅读时间需要 22 分钟。

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:

    Git文档:

  • Git Tagging Chapter:

    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 tagv1.0v2.0v3.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.1v2.0.2v2.0.3v2.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 tagv1.0v2.0v3.0v4.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 tagv1.0v2.0v3.0v4.0v4.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.0tag v4.0Tagger: John Cash 
Date: Mon Sat 28 15:00:25 2017 -0700release version 4.0commit da43a5fss745av88d47839247990022a98419093Author: John Cash
Date: Fri Feb 20 20:30:05 2015 -0700 finished details

If the tag you are watching is a lightweight tag, you’ll only see the refered commit data:

如果您正在查看的标签是轻量级标签,则您只会看到引用的提交数据:

$ git show v1.4-lwcommit da43a5f7389adcb9201ab0a289c389ed022a910bAuthor: John Cash 
Date: Fri Feb 20 20:30:05 2015 -0700 finished 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=onelineac2998acf289102dba00823821bee04276aad9ca added products sectiond09034bdea0097726fd8383c0393faa0072829a7 refactorizationa029ac120245ab012bed1ca771349eb9cca01c0b modified stylesda43a5f7389adcb9201ab0a289c389ed022a910b finished details0adb03ca013901c1e02174924486a08cea9293a2 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 tagv1.0v2.0v3.0v3.5v4.0v4.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.0Counting 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 --tagsCounting 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.3Note: checking out 'v0.0.3'.You are in 'detached HEAD' state. You can look around, make experimentalchanges and commit them, and you can discard any commits you make in thisstate 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 tagv0.0.1v0.0.3v0.0.4

更多信息 (More Information)

资料来源 (Sources)

Git documentation:

Git文档:

翻译自:

git 列出标签

转载地址:http://llrwd.baihongyu.com/

你可能感兴趣的文章
MyEclipse 8.X 通用算法
查看>>
selenium.Phantomjs设置浏览器请求头
查看>>
分布式数据库如何选择,几种分布式数据库优缺点一览
查看>>
BZOJ 4443: 小凸玩矩阵【二分图】
查看>>
苹果 OS X制作u盘启动盘
查看>>
Jquery便利对象
查看>>
MVC: Connection String
查看>>
idea常用设置汇总
查看>>
Node.SelectNodes
查看>>
Lambda表达式语法进一步巩固
查看>>
Vue基础安装(精华)
查看>>
Git 提交修改内容和查看被修改的内容
查看>>
PAT - 1008. 数组元素循环右移问题 (20)
查看>>
请求出现 Nginx 413 Request Entity Too Large错误的解决方法
查看>>
配置php_memcache访问网站的步骤
查看>>
hibernate的id生成策略
查看>>
树莓派3B+学习笔记:5、安装vim
查看>>
[Spfa][bfs] Jzoj P5781 秘密通道
查看>>
企业帐号进行IPA的打包、分发、下载安装的详细流程(转载)
查看>>
《项目架构那点儿事》——快速构建Junit用例
查看>>