This article introduces Git installation and use on MAC. Like most VCS, Git can tag versions at a point in time. Git tagging command

directory

Create a label. 3. Switch a label. 4

First, list the label

  • 1. The command to list existing labels is very simple, terminal input:

git tag
Copy the code

Output:

WMBdeMacBook-Pro:LearnGit WENBO$ git tag
v1.0.0
Copy the code
  • 2. If there are too many labels, it can be filtered. Terminal input:

git tag -l 'v1.0. *'
Copy the code

Output:

WMBdeMacBook-Pro:LearnGit WENBO$ git tag -l 'v1.0. *'
v1.0.0
Copy the code

2. Create a label

Git uses two types of tags: Lightweight and annotated. The default tag is attached to the latest commit. What if you want to tag the previous commit?

  • 1. First, switch to the branch that needs to be tagged

  • See the branch
git branch
Copy the code

Terminal output:

WMBdeMacBook-Pro:LearnGit WENBO$ git branch
* master
Copy the code
  • Switch to the Master branch
git checkout master
Copy the code

Terminal output:

WMBdeMacBook-Pro:LearnGit WENBO$ git checkout master
Already on 'master'
Your branch is up-to-date with 'origin/master'.
Copy the code

The switch to the Master branch was successful.

  • 2, create a lightweight label, terminal input:

Git tag v1.0.1Copy the code

Git tag:

WMBdeMacBook-Pro:LearnGit WENBO$ git tag
v1.0.0
v1.0.1
Copy the code

It has been created successfully.

  • 3, create a label with annotations, terminal input:

git tag -aV1.0.1 -m'My version v1.0.1'
Copy the code

Git tag

WMBdeMacBook-Pro:LearnGit WENBO$ git tag
v1.0.0
v1.0.1
Copy the code

The system has been created successfully.

  • 4. Tag the history commit

  • View the Commit Log

To view detailed logs, enter:

git log
Copy the code

Or thumbnail display log, terminal input:

git log --pretty=oneline --abbrev-commit
Copy the code

Terminal output:

WMBdeMacBook-Pro:LearnGit WENBO$ git log--pretty=oneline --abbrev-commit f113611 git First commit 1000218 Initial commitCopy the code
  • For this version, the commit ID is (06c0b98).
Git tag c0b98 v1.0.2 06Copy the code

Git tag

WMBdeMacBook-Pro:LearnGit WENBO$ git tag
v1.0.0
v1.0.1
v1.0.2
Copy the code

V1.0.2 Label submission of the historical version succeeded.

3. Switch labels

  • Git checkout [tagname] git checkout [tagname

Git checkout v1.0.0Copy the code

Terminal output:

WMBdeMacBook-Pro:LearnGit WENBO$ git checkout v1.0.0
Previous HEAD position was f113611... git 打标签
HEAD is now at ae3bbe9... First Commit
Copy the code
  • 2. View the label information

Git show v1.0.0Copy the code

Terminal output:

Wmbdemacbook-pro :LearnGit WENBO$git show v1.0.0 tag v1.0.0 Tagger: WENBO <[email protected]> Date: Sun Jan 7 14:05:07 2018 + 0800 v1.0.0 version commit ae3bbe951f5b3e906310d59c123880db7d6c5558 Author: wenbo <[email protected]> Date: Sat Jan 6 15:53:41 2018 +0800 First Commit diff --git a/LearnGitDemo/LearnGitDemo.xcodeproj/project.pbxproj b/LearnGitDemo/LearnGitDemo.xcodeproj/project.pbxproj new file mode 100644 index 0000000.. 60 b939d - + + + b / / dev/null LearnGitDemo/LearnGitDemo xcodeproj/project pbxproj @ @ - 0, 0 + 1327 @ @ + / /! $*UTF8*$! +{ + archiveVersion = 1; + classes = { :Copy the code

4. Delete labels

  • 1, delete the local label, terminal input:

 git tag -d v1.0.1
Copy the code

Git tag:

WMBdeMacBook-Pro:LearnGit WENBO$ git tag -dV1.0.1 does tag'v1.0.1' (was f113611)
WMBdeMacBook-Pro:LearnGit WENBO$ git tag
v1.0.0
Copy the code

You have successfully deleted it.

  • 2. Delete the remote label

  • Delete the local label first
 git tag -d v1.0.2
Copy the code

Git tag

WMBdeMacBook-Pro:LearnGit WENBO$ git tag
v1.0.0
v1.0.1
Copy the code
  • Deleting a Remote Label
Git push origin: refs/tags/v1.0.2Copy the code

Terminal output:

WMBdeMacBook - Pro: LearnGit WENBO $git push origin: refs/tags/v1.0.2 To https://github.com/wenmobo/LearnGit.git - [does] v1.0.2 WMBdeMacBook - Pro: LearnGit WENBO $Copy the code

Then check it out on GitHub:

5. Push the label to remote

  • 1. Push the specified version to remote

Here is the previous push tag, now test push v1.0.1 on GitHub.

Git push origin v1.0.1Copy the code

Terminal output:

Wmbdemacbook-pro :LearnGit WENBO$git Push Origin v1.0.1 Objects: 1, done. 100% (1/1), 160 bytes | 0 bytes/s, done. Total 1 (delta 0), Reused zero (0) delta To https://github.com/wenmobo/LearnGit.git * [new tag] v1.0.1 - > v1.0.1Copy the code

Check it out on GitHub:

  • 2. Push all local labels that have not been pushed to remote devices at one time

Git tag git tag

WMBdeMacBook-Pro:LearnGit WENBO$ git tag
v1.0.0
v1.0.1
v1.0.2
Copy the code

V1.0.2 has not been uploaded to GitHub.

git push origin --tags
Copy the code

Terminal output:

WMBdeMacBook-Pro:LearnGit WENBO$ git push origin --tags Total 0 (delta 0), Reused zero (0) delta To https://github.com/wenmobo/LearnGit.git * [new tag] v1.0.2 - > v1.0.2Copy the code

GitHub also uploaded successfully:

Pay attention to

  • First upload may require you to enter your GitHub account and password.

conclusion

Finally finish sorting out Git tagging common commands, sorting through, I feel I am familiar with Git operation again. I see that some organizations and some of them are using tag to version manage their open source libraries. For some third-party libraries that I am concerned about, I can’t help but look at the tags list and then check the updated content. Write an article to record yourself, if you can use it later, convenient for yourself to consult, I hope to be helpful to you. If there is something wrong, you are welcome to criticize and correct.

Refer to the article

  • The git tag command tags the current branch
  • Git tag
  • Label management