GitHub tag的使用

# tag的使用

## 显示tag

	$ git tag
	v0.1
	v1.3


## 搜索特定的tag
	
	$ git tag -l ’v1.4.2.*’
	v1.4.2.1
	v1.4.2.2
	v1.4.2.3
	v1.4.2.4

## 建立tag
	
tag主要有两类:

1. lightweight
	- 轻量级的 
	- "just a pointer to a specific commit"
2. annotated 
	- 带注释的 
	- "stored as full objects in the Git database"
	- contain the tagger name, e-mail, and date; have a tagging message;
	- generally recommended

## Annotated Tags

创建Annotated Tags很简单,只需-a就行,-m写上msg

	$ git tag -a v1.4 -m ’my version 1.4’
	$ git tag
	v0.1
	v1.3
	v1.4

显示tag内容

	$ git show v1.4
	tag v1.4
	Tagger: Scott Chacon <schacon@gee-mail.com>
	Date: Mon Feb 9 14:45:11 2009 -0800
	my version 1.4
	commit 15027957951b64cf874c3557a0f3547bd83b3ff6
	Merge: 4a447f7... a6b4c97...
	Author: Scott Chacon <schacon@gee-mail.com>
	Date: Sun Feb 8 19:02:46 2009 -0800
	Merge branch ’experiment’

## Lightweight Tags

lw tags don’t supply the -a, -s, or -m option

	$ git tag v1.4-lw
	$ git tag
	v0.1
	v1.3
	v1.4
	v1.4-lw
	v1.5

显示lw tags 和commit差不多,没多少信息

	$ git show v1.4-lw
	commit 15027957951b64cf874c3557a0f3547bd83b3ff6
	Merge: 4a447f7... a6b4c97...
	Author: Scott Chacon <schacon@gee-mail.com>
	Date: Sun Feb 8 19:02:46 2009 -0800
	Merge branch ’experiment’

## 为过去的commit添加tag

从git log中获取commit id

	$ git log --pretty=oneline
	166ae0c4d3f420721acbb115cc33848dfcc2121a started write support
	9fceb02d0ae598e95dc970b74767f19372d61af8 updated rakefile
	964f16d36dfccde844893cac5b347e7b3d44abbc commit the todo
	8a5cbc430f1a9c3d00faaeffd07798508422908a updated readme

在最后一个参数写入commit id

	$ git tag -a v1.2 9fceb02

## 删除tag

使用-d或者--delete

	D:MarkdownDemonstration [master]> git tag
	tempTag
	v0.8
	v1.0
	D:MarkdownDemonstration [master]> git tag --delete tempTag
	Deleted tag 'tempTag' (was 66aaff1)

## Rename a tag
	
First you need to build an alias of the old tag name:

	git tag new_tag_name old_tag_name

Then you need to delete the old one locally:

	git tag -d old_tag_name

Then delete the tag on you remote location(s):

	# Check your remote sources:
	git remote -v
	# The argument (3rd) is your remote location,
	# the one you can see with `git remote`. In this example: `origin`
	git push origin :refs/tags/old_tag_name

此时本地还剩下一个tag,即new_tag_name,
需要换个commit来tag的话就删了这个new_tag_name,就可以新指定了

## 上传tag
	
tag默认不上传,需要自己制定上传 git push origin [tagname]

	传一个
	$ git push origin v1.5
	全传
	$ git push origin --tags



原文地址:https://www.cnblogs.com/jun14/p/3425009.html