Git: tag 标签操作

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

1. 打标签

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

轻量标签:

$ git tag v1.3.2

带注释的标签:

$ git tag -a v1.3.3 -m “The 1.3.3 version”

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

2. 列出本地所有标签

$ git tag
v1.3.1
v1.3.2
v1.3.3

3. 查看标签信息

$ git show v1.3.3

4. 搜索标签

$ git tag -l "v1.3.*"
v1.3.1
v1.3.2
v1.3.3

其中的“l”就是 list的意思,比如上面会搜索出v1.3.x的版本tag

5. 切换到指定标签的版本

$ git checkout -b test_version v1.3.2
Switched to a new branch 'test_version'

其中的“test_version”就是新切换的分支的名字,v1.3.2 就是之前v1.3.2版本打的tag名字。

PS: 也可以直接使用 git checkout v1.3.2 , 但这样会使当前的分支处于游离态(‘detached HEAD’ state), 如果你需要对旧版本进行修改,最好像上面一样创建一个新的分支。

6. 给历史提交打标签

$ git log --oneline
c39f9f1 (HEAD -> feature/like_samsung_ui_3, tag: v1.3.3) android:Refactor: update the jump logic of the device select interface
515a718 android:Feature: Display device type icon according to device type
77c01e5 (tag: v1.3.2, test_version) android:Feature: Add engineering mode
d2f1956 (tag: v1.3.1) android:Bugfix: Fixed the problem that the headset mode cannot be switched by double-clicking the MFB button
0562f99 android:Feature: Add some code for create & destroy SCO link
e02f711 android:Feature: establish an A2DP link while connecting the device
5e2d67d android:Feature: modify the name of eq (eq0, eq1, eq2) to the corresponding actual effect name
01c0ad0 android:Feature: Supports orderly sending of multiple command
9286c66 android:BugFix: Fixed the problem that RadioGroup#onCheckedChanged() was called multiple times
5be1cb7 android:BugFix: Fixed the problem that get audio eq index failed
a290b93 android:Feature: add new command: CMD_HA_APT_EQ_INDEX_SET, CMD_HA_APT_EQ_INDEX_GET
bad0659 android:Feature: add command CMD_HA_GET_APT_VOL_LEVEL & CMD_HA_SET_APT_VOL_LEVEL
92e6a89 android:Refactor: use DSP-APT EQ parameter settings
5026f7a (feature/like_samsung_ui_2) android:BugFix: Fixed the response timeout issue on OPPO reno CPH1917
52a586b android:Feature: add eq mode settings implementation
edc409b android:Feature: add LLAPT command implementation

$ git tag -a v1.3.0 -m "The 1.3.0 version" 0562f99

$ git log --oneline
c39f9f1 (HEAD -> feature/like_samsung_ui_3, tag: v1.3.3) android:Refactor: update the jump logic of the device select interface
515a718 android:Feature: Display device type icon according to device type
77c01e5 (tag: v1.3.2, test_version) android:Feature: Add engineering mode
d2f1956 (tag: v1.3.1) android:Bugfix: Fixed the problem that the headset mode cannot be switched by double-clicking the MFB button
0562f99 (tag: v1.3.0) android:Feature: Add some code for create & destroy SCO link
e02f711 android:Feature: establish an A2DP link while connecting the device
5e2d67d android:Feature: modify the name of eq (eq0, eq1, eq2) to the corresponding actual effect name
01c0ad0 android:Feature: Supports orderly sending of multiple command
9286c66 android:BugFix: Fixed the problem that RadioGroup#onCheckedChanged() was called multiple times
5be1cb7 android:BugFix: Fixed the problem that get audio eq index failed
a290b93 android:Feature: add new command: CMD_HA_APT_EQ_INDEX_SET, CMD_HA_APT_EQ_INDEX_GET
bad0659 android:Feature: add command CMD_HA_GET_APT_VOL_LEVEL & CMD_HA_SET_APT_VOL_LEVEL
92e6a89 android:Refactor: use DSP-APT EQ parameter settings
5026f7a (feature/like_samsung_ui_2) android:BugFix: Fixed the response timeout issue on OPPO reno CPH1917
52a586b android:Feature: add eq mode settings implementation
edc409b android:Feature: add LLAPT command implementation

首先用  git log --oneline  指令找出历史提交的commit id, 然后在打tag的指令末尾加上这个commit id 即可。

7. 删除标签

$ git tag -d v1.3.0
Deleted tag 'v1.3.0' (was 91cc764)

8. 推送标签到远程Git服务器

推送一条标签信息

$ git push origin v1.3.5

推送本地所有标签信息

$ git push origin –tags

 

参考链接:

1. git 修改标签名称_git-tag 标签相关操作

2. Git 基础 - 打标签

 

posted @ 2021-03-30 15:05  夜行过客  阅读(567)  评论(0编辑  收藏  举报