Operation Management of Git tags in linux

Source: Internet
Author: User
Tags gnupg gpg tag name tagname


When we publish a version, we usually start with a label in the repository, so that we have the only one that determines the time of the tag. Whenever you take a label version, you take the historical version of the label moment. Therefore, the label is also a snapshot of the version library.
Git's tag is a snapshot of the version library, but it's a pointer to a commit (like a branch, right?). But the branches can be moved and the labels cannot be moved, so creating and deleting tags is instantaneous.

Creating labels

Tagging in git is very simple, first, switch to the branch you want to label:

$ git Branch
* Dev
Master
$ git Checkout Master
Switched to branch ' master '
Then, knock on the command git tag name to make a new label:

$ git Tag v1.0
You can use the command git tag to view all tags:

$ git tag
v1.0
The default label is on the most recently committed commit. Sometimes, if forget to play the label, for example, now is Friday, but should be in Monday, the label did not hit, how to do?
The method is to find the commit ID of the history commit, and then hit on it:

$ git log--pretty=oneline--abbrev-commit
6A5819E merged bug Fix 101
CC17032 Fix Bug 101
7825a50 Merge with No-ff
6224937 Add Merge
59BC1CB Conflict Fixed
400b400 & Simple
75a857c and simple
FEC145A Branch Test
D17efd8 Remove Test.txt
...
For example, to label the "add merge" this time, its corresponding commit ID is "6224937", type the command:

$ git tag v0.9 6224937
Then use the command git tag to view the tags:

$ git tag
v0.9
v1.0
Note that the labels are not listed in chronological order, but are sorted alphabetically. You can use Git show tagname to view tag information:

$ git show v0.9
Commit 622493706AB447B6BB37E4E2A2F276A20FED2AB4
Author:michael Liao <askxuefeng@gmail.com>
Date:thu Aug 22 11:22:08 2013 +0800

Add Merge
...
As you can see, "v0.9" is actually on the "add merge" submission.
You can also create a label with a description, specify a label name with-A, and-m to specify the descriptive text:

$ git tag-a v0.1-m "version 0.1 released" 3628164
Use the command git show tagname to see the explanatory text:

$ git show v0.1
Tag v0.1
Tagger:michael Liao <askxuefeng@gmail.com>
Date:mon Aug 26 07:28:11 2013 +0800

Version 0.1 released

Commit 3628164FB26D48395383F8F31179F24E0882E1E0
Author:michael Liao <askxuefeng@gmail.com>
Date:tue Aug 20 15:11:49 2013 +0800

Append GPL
...
You can also sign a label by-s with the private key:

$ git tag-s v0.2-m "signed version 0.2 released" fec145a
The signature is signed in PGP, so you must first install GPG (GnuPG), if you do not find GPG, or if you do not have a GPG key pair, you will get an error:

Gpg:signing Failed:secret Key Not available
ERROR:GPG failed to sign the data
Error:unable to sign the tag
If the error is correct, refer to the GNUPG Help document configuration key.
Use the command git show tagname to see PGP signature information:

$ git show v0.2
Tag v0.2
Tagger:michael Liao <askxuefeng@gmail.com>
Date:mon Aug 26 07:28:33 2013 +0800

Signed version 0.2 released
-----BEGIN PGP SIGNATURE-----
Version:gnupg v1.4.12 (Darwin)

Iqecbaabagagbqjsgpmhaaojepuxhydahbpt4qqiakehfr3bo ...
-----End PGP SIGNATURE-----

Commit fec145accd63cdc9ed95a2f557ea0658a2a6537f
Author:michael Liao <askxuefeng@gmail.com>
Date:thu Aug 22 10:37:30 2013 +0800

Branch Test
...
A label that is signed with PGP is not forged, because the PGP signature can be verified. The method of verifying the signature is more complex, and is not described here.

Action Label

If the label is wrong, you can also delete:

$ git tag-d v0.1
Deleted tag ' v0.1 ' (was e078af9)
Because the labels you create are only stored locally, they are not automatically pushed to the remote. Therefore, the wrong label can be safely removed locally.
If you want to push a label to a remote, use the command GIT push Origin tagname:

$ GIT push Origin v1.0
Total 0 (Delta 0), reused 0 (Delta 0)
To Git@github.com:michaelliao/learngit.git
* [New tag] v1.0-> v1.0
Or, a one-time push all has not been pushed to the remote local label:

$ GIT push origin--tags
Counting 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
If the label has been pushed to the remote, remove the remote label to make it a bit cumbersome to remove it from the local area first:

$ git tag-d v0.9
Deleted tag ' v0.9 ' (was 6224937)
Then, remove from the remote. The Delete command is also push, but the format is as follows:

$ git push origin:refs/tags/v0.9
To Git@github.com:michaelliao/learngit.git
-[deleted] v0.9
To see if the tag is really removed from the remote library, you can login to GitHub view.
Summary

Command git tag name is used to create a new label, the default is head, or you can specify a commit ID;
-A tagname-m "Blablabla ..." can specify the label information;
-S Tagname-m "Blablabla ..." can be signed with PGP tag;
command git tag to view all tags;
Command GIT push origin tagname can push a local label;
Command git push origin–tags can push all the local tags that have not been pushed;
Command git tag-d tagname can delete a local label;
Command git push origin:refs/tags/tagname can delete a remote tag.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.