[Git] Git label operation

In projects that use Git as a code management tool, when a new version is launched, a version label is usually created. Git tags are the identification of project milestones and key points in the historical state. We can view the code of a certain version of history according to the project tag, or roll back the code according to the project tag. Git tags play a very important role in project release and version management.

1. Create a new Git tag

Create a new tag using the git tag -a tag name command:

git tag -a v1.0 -m 'v1.0的备注信息'

Through the above naming, the v1.0 label is created, and the remark information is added using the -m parameter

Create a signed label

The label created by the git tag -a command does not have a signature. If you need to create a signed label, you can use the git tag -s label name command. The signed label will use the gpg private key to encrypt the label to ensure the security of the label.

git tag -s v1.0 -m 'sign v1.0 tag'

After creating a signature tag, you can use git tag -v tag name to verify the legitimacy of the tag:

git tag -v v1.0

2. Push tags to remote server

After adding a tag, the tag will be added to the git local code repository. To push a tag to a remote server, you need to push it to the remote server. Using the git push command can only push the submitted code, not the tag. You need to add the --tags parameter to submit the tag:

git push --tags

3. View tags

View all tags in the project using the git tag command, which will list all added tags:

git tag

The git tag command will simply display the tag name. If you need to view the description information , use the following command:

git tag -ln

When rolling back the version, we need to find the corresponding commit submission information according to the label name. git show tag name will list the tag information, and the detailed commit information below:

git show v1.0

4. Delete tags

The tag submission is wrong, or you want to delete a tag long ago, you can delete the tag with the git tag -d tag name command:

git tag -d v1.0

Guess you like

Origin blog.csdn.net/zhoulizhu/article/details/113248358