git tag management (reproduced)

From: http://www.centoscn.cn/4370.html


Briefly

The tag is similar to the snapshot function, which can label the repository to record the state of the repository at a certain moment. You can also revert to this state at any time.

operate

Switch to the master branch

[root@www azhen]# git checkout master 
already on 'master'
[root@www azhen]# git branch
* master
[root@www azhen]# ls
2.txt azhen README.md

Tag master v1.0 and see what tags are there

[root@www azhen]# git tag v1.0
[root@www azhen]# git tag
v1.0

View the information in the label

[root@www azhen]# git show v1.0
commit 2bf9f5b5945189844022910fb2a6a619a2798528
Author: azhen <[email protected]>
Date: Sat Apr 7 03:48:03 2018 +0800

add 2.txt

diff --git a/2.txt b/2.txt
new file mode 100644
index 0000000..8d7c5b6
--- /dev/null
+++ b/2.txt
@@ -0,0 +1 @@
+www.centoscn.cn

The tag is tagged for commits, so it can be tagged for historical commits

[root@www azhen]# git log --pretty=oneline --abbrev-commit
2bf9f5b add 2.txt
602096f add README

针对历史commit打标签

[root@www azhen]# git tag v1.1 602096f 
[root@www azhen]# git tag
v1.0
v1.1

可以对标签进行描述

[root@www azhen]# git tag -a v1.2 -m "最新代码" 2bf9f5b 
[root@www azhen]# git tag
v1.0
v1.1
v1.2

查看详细信息

[root@www azhen]# git show v1.2
tag v1.2
Tagger: azhen <[email protected]>
Date: Wed Apr 11 18:13:45 2018 +0800

最新代码

commit 2bf9f5b5945189844022910fb2a6a619a2798528
Author: azhen <[email protected]>
Date: Sat Apr 7 03:48:03 2018 +0800

add 2.txt

diff --git a/2.txt b/2.txt
new file mode 100644
index 0000000..8d7c5b6
--- /dev/null
+++ b/2.txt
@@ -0,0 +1 @@
+www.centoscn.cn

删除标签

[root@www azhen]# git tag -d v1.0
已删除 tag 'v1.0'(曾为 2bf9f5b)

推送指定标签到远程

[root@www azhen]# git push origin v1.2
Username for 'http://gitlab.centoscn.cn': root
Password for 'http://[email protected]': 
Counting objects: 1, done.
Writing objects: 100% (1/1), 173 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To http://gitlab.centoscn.cn/root/azhen.git
 * [new tag] v1.2 -> v1.2

Check

git tag management (gitlab as an example)git tag management (gitlab as an example)

At the same time, if there are multiple branches, you can also push at the same time

[root@www azhen]# git push --tag origin
Username for 'http://gitlab.centoscn.cn': root
Password for 'http://[email protected]':
Total 0 (delta 0), reused 0 (delta 0)
To http://gitlab.centoscn.cn/root/azhen.git
 * [new tag] v1.1 -> v1.1

git tag management (gitlab as an example)

If you delete a label locally, you need to do this if you want to delete it remotely

[root@www azhen]# git push origin :refs/tags/v1.1
Username for 'http://gitlab.centoscn.cn': root
Password for 'http://[email protected]':
To http://gitlab.centoscn.cn/root/azhen.git
 - [deleted] v1.1

just want to delete local

[root@www azhen]# git tag
v1.1
v1.2
[root@www azhen]# git tag v1.1 -d
Removed tag 'v1.1' (was 602096f)
[root@www azhen]# git tag
v1.2

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325771443&siteId=291194637