git Label management _ Power node Java College Collation

  • 2020-06-19 12:17:33
  • OfStack

When we release a release, we usually put a tag (tag) in the repository first, so that only 1 determines the version at which the tag was made. Whenever you retrieve a version of a tag in the future, you're pulling out a historical version of the time you tagged it. So, the tag is also a snapshot of the version library.

The Git tag is a snapshot of the repository, but it's really just a pointer to some commit. But the branch can move, the label can't), so creating and removing labels is instantaneous.

Git has commit, so why introduce tag?
"Please package and release the version of last week 1. commit number is 6a5819e..."
"It's hard to find a string of 78 bad Numbers!"
If there is another way:
"Please package and release the version of last week's 1, version es20EN1.2."
"Ok, just follow tag v1.2 to find commit!"
So tag is an easy to remember meaningful name tied to a certain commit.

Create a label

Tagging in Git is very simple. First, switch to the branch that needs to be tagged:


$ git branch
* dev
 master
$ git checkout master
Switched to branch 'master'

Then, type the command git tag < name > You can put a new tag:


$ git tag v1.0

You can view all tags with the command git tag:


$ git tag
v1.0

The default tag is typed on the most recently submitted commit. Sometimes, if you forget to tag, for example, it's Week 5 now, but there should be dozens of tags left on Week 1, what do you do?

The method is to find the history submitted commit id and type:


$ 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 submission, the corresponding commit id is 6224937, type the command:


$ git tag v0.9 6224937

Use the command git tag to view the tag:


$ git tag
v0.9
v1.0

Note that the tags are not listed chronologically, but alphabetically. You can use git show < tagname > View label 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 was indeed typed on add merge's submission.
You can also create tags with instructions, specifying the tag name with -ES90en and the caption with -ES91en:


$ git tag -a v0.1 -m "version 0.1 released" 3628164

Use the command git show < tagname > You can see the caption:


$ 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 1 tag with private key via -ES105en:


$ git tag -s v0.2 -m "signed version 0.2 released" fec145a

The signature is PGP signature, therefore, gpg (GnuPG) must be installed first. If gpg is not found, or there is no gpg key pair, an error will be reported:


$ git tag v1.0
0

If an error is reported, refer to the GnuPG Help document to configure Key.
Use the command git show < tagname > You can see the PGP signature information:


$ git tag v1.0
1

Labels signed with PGP cannot be forged because the PGP signature can be verified. The method of verifying a signature is more complex and will not be covered here.

Operating the label

If the tag is incorrectly typed, it can also be deleted:


$ git tag v1.0
2

Because created labels are stored locally, they are not automatically pushed to remote locations. So, mislabeled tags can be safely removed locally.
To push a TAB remotely, 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, all local labels that have not been pushed to the remote location in the first push:


$ git tag v1.0
4

If the label has been pushed to the remote, please delete the remote label from the local:


$ git tag v1.0
5

Then, delete from the remote. The delete command is also push, but in the following format:


$ git tag v1.0
6

To see if the tag was actually removed from the remote library, go to GitHub.


Related articles: