Git tutorial Learning (vii)-tag Management _git Learning

Source: Internet
Author: User
Tags gnupg gpg pack tagname

When we publish a version, we usually start with a tag in the repository, which is the only way to determine the version of the label moment. 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 actually a pointer to a commit (like the branch is right.) But the branches can be moved and the labels cannot be moved, so creating and deleting tags is instantaneous.

Why do you want to introduce tag when git has a commit?

"Please pack the Monday version of the release, the commit is 6a5819e ..."

"A bunch of messy numbers are not easy to find. ”

If you change one way:

"Please pack the Monday version of the release, the version number is v1.2"

"OK, follow tag v1.2 to find a commit." ”

So, tag is a meaningful name that's easy to remember, tied to a commit. 1: Create a label

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> can 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 you forget to label, for example, now is Friday, but should be in Monday to play 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
cc17032 fix bug
7825a50 merge with n O-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> view tag information:

$ git show v0.9
commit 622493706ab447b6bb37e4e2a2f276a20fed2ab4
Author:michael Liao < Askxuefeng@gmail.com>
Date:   Thu Aug 11:22:08 2013 +0800

    Add Merge
...

As you can see, v0.9 did hit the add merge on this 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> can 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 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 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. Summary

Command git tag <name> to create a new label, the default is head, or you can specify a commit ID;

Git tag-a <tagname>-M "Blablabla ..." can specify tag information;

Git tag-s <tagname>-M "Blablabla ..." can be signed with PGP tags;

command git tag to view all tags. 2: Operation 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< c11/>* [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 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.