赞
踩
1). 在local端新增tag,如果commit_id为空,默认以最新的commit_id为准
- $ git tag -a [tag_name] [commit_id]
- $ git tag -a 1.0.1 -m '.' # 创建带附注的附注标签,m参数可选
2). 切换标签
- $ git checkout 1.0.1 #跳转到某标签
- $ git show 1.0.1 #查看标签版本信息
这块需要注意一下,使用checkout切换到某标签时,git会提示你处于一个空分支,需要使用-b来创建一个分支,以便进行分支管理。
- $ git tag -a tag_temp a8a7d63d887bc65c23d0407c2569dc2f796b06a8 # 在某个commit_id上创建tag,写注释
- $ git tag # 查看tag
- $ git checkout tag_temp # 切换到指定tag,git会提示你如下
- Note: checking out 'tag_temp'.
-
- 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.
-
- If you want to create a new branch to retain commits you create, you may
- do so (now or later) by using -b with the checkout command again. Example:
-
- git checkout -b <new-branch-name>
-
- HEAD is now at a8a7d63... xxxxx
-
- $ git checkout -b temppp # 在tag到临时分支上创建本地分支
或者直接根据tag创建分支
$ git checkout -b bugfix-tempp tag_temp
3). 在remote端新增tag
- $ git push origin [tag_name]
- $ git push origin --tag # 一次將所有tag push上去
4). 在local端刪除tag
$ git tag -d [tag_name]
5). 在remote端刪除tag
$ git push origin :refs/tags/[tag_name]
6). 后期打标签
你也可以对过去的提交打标签。 假设提交历史是这样的:
- $ git log --pretty=oneline
- 15027957951b64cf874c3557a0f3547bd83b3ff6 Merge branch 'experiment'
- a6b4c97498bd301d84096da251c98a07c7723e65 beginning write support
- 0d52aaab4479697da7686c15f77a3d64d9165190 one more thing
- 6d52a271eda8725415634dd79daabbc4d9b6008e Merge branch 'experiment'
- 0b7434d86859cc7b8c3d5e1dddfed66ff742fcbc added a commit function
- 4682c3261057305bdd616e23b64b0857d832627b added a todo file
- 166ae0c4d3f420721acbb115cc33848dfcc2121a started write support
- 9fceb02d0ae598e95dc970b74767f19372d61af8 updated rakefile
- 964f16d36dfccde844893cac5b347e7b3d44abbc commit the todo
- 8a5cbc430f1a9c3d00faaeffd07798508422908a updated readme
现在,假设在 v1.2 时你忘记给项目打标签,也就是在 “updated rakefile” 提交。 你可以在之后补上标签。 要在那个提交上打标签,你需要在命令的末尾指定提交的校验和(或部分校验和):
$ git tag -a v1.2 9fceb02
————————————————
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。