美文网首页
git给分支添加tag标签

git给分支添加tag标签

作者: 我的昵称好听吗 | 来源:发表于2018-12-03 10:20 被阅读0次

$ git tag # 在控制台打印出当前仓库的所有标签

git标签分为两种类型:轻量标签和附注标签。轻量标签是指向提交对象的引用,附注标签则是仓库中的一个独立对象。建议使用附注标签。

创建轻量标签

$ git tag v0.1.2-light

标签可以针对某一时间点的版本做标记,常用于版本发布。

  • 列出标签

$ git tag # 在控制台打印出当前仓库的所有标签

  • 打标签

git标签分为两种类型:轻量标签和附注标签。轻量标签是指向提交对象的引用,附注标签则是仓库中的一个独立对象。建议使用附注标签。

创建轻量标签

$ git tag v0.1.2-light

创建附注标签

$ git tag -a v0.1.2 -m “0.1.2版本”

创建轻量标签不需要传递参数,直接指定标签名称即可。
创建附注标签时,参数a即annotated的缩写,指定标签类型,后附标签名。参数m指定标签说明,说明信息会保存在标签对象中。

  • 切换到标签

与切换分支命令相同,用git checkout [tagname]
查看标签信息
git show命令可以查看标签的版本信息:
$ git show v0.1.2

  • 删除标签

误打或需要修改标签时,需要先将标签删除,再打新标签。
$ git tag -d v0.1.2 # 删除标签

参数d即delete的缩写,意为删除其后指定的标签。


如果标签打错了,也可以删除:

$ git tag -d v0.1Deleted tag 'v0.1' (was e078af9)

因为创建的标签都只存储在本地,不会自动推送到远程。所以,打错的标签可以在本地安全删除。

如果要推送某个标签到远程,使用命令git push origin <tagname>

$ git push origin v1.0Total 0 (delta 0), reused 0 (delta 0)To git@github.com:michaelliao/learngit.git * [new tag]         v1.0 -> v1.0

或者,一次性推送全部尚未推送到远程的本地标签:

$ git push origin --tagsCounting objects: 1, done.Writing objects: 100% (1/1), 554 bytes, done.Total 1 (delta 0), reused 0 (delta 0)To git@github.com:michaelliao/learngit.git * [new tag]         v0.2 -> v0.2 * [new tag]         v0.9 -> v0.9

如果标签已经推送到远程,要删除远程标签就麻烦一点,先从本地删除:

$ git tag -d v0.9Deleted tag 'v0.9' (was 6224937)

然后,从远程删除。删除命令也是push,但是格式如下:

$ git push origin :refs/tags/v0.9To git@github.com:michaelliao/learngit.git - [deleted]         v0.9

要看看是否真的从远程库删除了标签,可以登陆GitHub查看。

  • 给指定的commit打标签

打标签不必要在head之上,也可在之前的版本上打,这需要你知道某个提交对象的校验和(通过git log获取)。

补打标签

$ git tag -a v0.1.1 9fbc3d0


默认标签是打在最新提交的commit上的。有时候,如果忘了打标签,比如,现在已经是周五了,但应该在周一打的标签没有打,怎么办?

方法是找到历史提交的commit id,然后打上就可以了:

$ git log --pretty=oneline --abbrev-commit6a5819e merged bug fix 101cc17032 fix bug 1017825a50 merge with no-ff6224937 add merge59bc1cb conflict fixed400b400 & simple75a857c AND simplefec145a branch testd17efd8 remove test.txt...

比方说要对add merge这次提交打标签,它对应的commit id是6224937,敲入命令:

$ git tag v0.9 6224937

再用命令git tag查看标签:

$ git tagv0.9v1.0

注意,标签不是按时间顺序列出,而是按字母排序的。可以用git show <tagname>查看标签信息:

$ git show v0.9commit 622493706ab447b6bb37e4e2a2f276a20fed2ab4Author: Michael Liao <askxuefeng@gmail.com>Date:   Thu Aug 22 11:22:08 2013 +0800     add merge...

可以看到,v0.9确实打在add merge这次提交上。

  • 标签发布

通常的git push不会将标签对象提交到git服务器,我们需要进行显式的操作:
git push origin v0.1.2 # 将v0.1.2标签提交到git服务器 git push origin –tags # 将本地所有标签一次性提交到git服务器

注意:如果想看之前某个标签状态下的文件,可以这样操作

1.git tag 查看当前分支下的标签

2.git checkout v0.21 此时会指向打v0.21标签时的代码状态,(但现在处于一个空的分支上)

image

你处于“脱离头”状态。 你可以环顾四周,做实验更改并提交它们,并且您可以放弃您在此提交的任何提交通过执行另一个结账而不影响任何分支。
如果你想创建一个新的分支来保留你创建的提交,你可以
(现在或以后)再次使用-b和checkout命令。 Example: git checkout -b <new-branch-name>

从当前的develop分支,切换到201712130927develop这个tag,现在处于一个空分支,

git checkout -b CurrentTimeBus201712130927 创建一个新分支CurrentTimeBus201712130927,这个新分支就是打201712130927develop标签时的代码状态。

////////////////////////////////////////////

usage: git tag [-a | -s | -u <key-id>] [-f] [-m <msg> | -F <file>] <tagname> [<head>]
or: git tag -d <tagname>...
or: git tag -l [-n[<num>]] [--contains <commit>] [--no-contains <commit>] [--points-at <object>]
[--format=<format>] [--[no-]merged [<commit>]] [<pattern>...]
or: git tag -v [--format=<format>] <tagname>...

-l, --list            list tag names
-n[<n>]               print <n> lines of each tag message
-d, --delete          delete tags
-v, --verify          verify tags

Tag creation options
-a, --annotate annotated tag, needs a message
-m, --message <message>
tag message
-F, --file <file> read message from file
-s, --sign annotated and GPG-signed tag
--cleanup <mode> how to strip spaces and #comments from message
-u, --local-user <key-id>
use another key to sign the tag
-f, --force replace the tag if exists
--create-reflog create a reflog

Tag listing options
--column[=<style>] show tag list in columns
--contains <commit> print only tags that contain the commit
--no-contains <commit>
print only tags that don't contain the commit
--merged <commit> print only tags that are merged
--no-merged <commit> print only tags that are not merged
--sort <key> field name to sort on
--points-at <object> print only tags of the object
--format <format> format to use for the output
-i, --ignore-case sorting and filtering are case insensitive

/////////////////////////////////////

原文地址: https://blog.csdn.net/jiaofeng_hou/article/details/78793854

相关文章

  • tag

    1、查看分支tag git tag 或者 git tag -l 2、打标签 git tag name ...

  • 【转载】git tag 相关

    【本文转自】git命令之git tag 给当前分支打标签 git tag — 标签相关操作 标签可以针对某一时间点...

  • Git 使用简记

    git 标签 添加标签git tag ,例:git tag v1.0 添加带有说明的标签git...

  • git相关常用命令

    git放弃修改相关操作 git删除未跟踪文件 git tag相关 查看本地标签 查看远程标签 给当前分支打标签 给...

  • git 分支打tag

    三.git 分支打tag 1.列出git上现有的所有标签。执行命令:git tag 2.为当前分支创建标签。执行命...

  • git给分支添加tag标签

    $ git tag # 在控制台打印出当前仓库的所有标签 git标签分为两种类型:轻量标签和附注标签。...

  • Git命令操作指南(二)

    Git命令解析(续) 1.查看标签 git tag 2.展示当前分支的最近的tag git describe --...

  • Git 之标签管理

    创建标签 1. git tag 在所处分支的最新一次提交上新建一个标签$ git tag v1...

  • Git 标签管理

    标签管理 创建标签 在Git中打标签需要先切换到需要打标签的分支上: 然后,敲命令 git tag ...

  • git 学习笔记(三)

    1.创建标签,首先切换到要打标签的分支$ git checkout master打一个新的标签$ git tag ...

网友评论

      本文标题:git给分支添加tag标签

      本文链接:https://www.haomeiwen.com/subject/xowecqtx.html