jagent@ubuntu:~/xin/user2$ git commit --allow-empty -m "blank commit."
[master 538e69d] blank commit.
jagent@ubuntu:~/xin/user2$ git tag mytag
jagent@ubuntu:~/xin/user2$ git tag -l my*
mytag
jagent@ubuntu:~/xin/user2$ cat .git/refs/tags/mytag
538e69dabcbc1ae8a7c30dd56c7ca7aa9c9293a2
jagent@ubuntu:~/xin/user2$ git cat-file -t mytag
commit
jagent@ubuntu:~/xin/user2$ git cat-file -t 538e69dabc
commit
jagent@ubuntu:~/xin/user2$ git cat-file -p mytag
tree e1daa3a207439f6ccedb4766d70e6efd7ef7f3ff
parent f1b513df6c4984b675bd37ea94c28f9d00dfc3b4
parent 0a5e50511aedff98ddb7485cd15be42bf7c9fe9d
author user2 <user2@122.com> 1605596666 +0800
committer user2 <user2@122.com> 1605596666 +0800
blank commit.
缺点很明显,没有说明描述,不知道谁创建的,何时创建的
git describe命令默认不使用轻量级版本描述字符串
使用--tags参数
jagent@ubuntu:~/xin/user2$ git describe --tags
mytag
2.带说明的里程碑
git tag -a/-m <msg> 和轻量级不同的是会创建一个tag对象 对象包含的内容有说明描述,创建人信息,创建时间
jagent@ubuntu:~/xin/user2$ git commit --allow-empty -m "blank commit for annotated tag test"
[master 7680a28] blank commit for annotated tag test
jagent@ubuntu:~/xin/user2$ git tag -m "my first annotated tag" mytag2
jagent@ubuntu:~/xin/user2$ git tag -l my* -n1
mytag blank commit.
mytag2 my first annotated tag
jagent@ubuntu:~/xin/user2$ git tag -l my* -n1
mytag blank commit.
mytag2 my first annotated tag
jagent@ubuntu:~/xin/user2$ cat .git/refs/tags/mytag2
533070b3f838240b92baab3b36c75811cb247d2f
jagent@ubuntu:~/xin/user2$ git cat-file -t mytags
fatal: Not a valid object name mytags
jagent@ubuntu:~/xin/user2$ git cat-file -t mytag2
tag
jagent@ubuntu:~/xin/user2$ git cat-file -p mytag2
object 7680a28f1ca6d6b8803afc0eb65a5580a3ce7b0b
type commit
tag mytag2
tagger user2 <user2@122.com> 1605598342 +0800
my first annotated tag
3.带签名的里程碑(了解)
在说明的里程碑的基础上多了一个GNUPG签名
使用参数-s或者-u<key-id>
安装gnupg
sudo aptitude install gnupg
jagent@ubuntu:~/xin/user2$ sudo apt-get install gnupg
Reading package lists... Done
Building dependency tree
Reading state information... Done
gnupg is already the newest version.
The following packages were automatically installed and are no longer required:
fastjar jarwrapper libjcommon-java libjfreechart-java libsctp1
libswingx-java linux-headers-4.2.0-27 linux-headers-4.2.0-27-generic
linux-image-4.2.0-27-generic linux-image-extra-4.2.0-27-generic lksctp-tools
tzdata-java
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 82 not upgraded.
jagent@ubuntu:~/xin/user2$ sudo aptitude install gnupg
The following packages will be REMOVED:
fastjar{u} jarwrapper{u} libjcommon-java{u} libjfreechart-java{u}
libsctp1{u} libswingx-java{u} lksctp-tools{u} tzdata-java{u}
0 packages upgraded, 0 newly installed, 8 to remove and 82 not upgraded.
Need to get 0 B of archives. After unpacking 4,805 kB will be freed.
Do you want to continue? [Y/n/?] Y
(Reading database ... 262268 files and directories currently installed.)
Removing jarwrapper (0.45ubuntu1) ...
Removing fastjar (2:0.98-5) ...
Removing libjfreechart-java (1.0.13-5) ...
Removing libjcommon-java (1.0.16-3) ...
Removing lksctp-tools (1.0.15+dfsg-1) ...
Removing libsctp1:amd64 (1.0.15+dfsg-1) ...
Removing libswingx-java (1:1.6.2-1) ...
Removing tzdata-java (2019a-0ubuntu0.14.04) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for install-info (5.2.0.dfsg.1-2) ...
Processing triggers for libc-bin (2.19-0ubuntu6.14) ...
jagent@ubuntu:~/xin/user2$ git commit --allow-empty -m "blank commit for GnuPG-signed tag test"
[master af223af] blank commit for GnuPG-signed tag test
jagent@ubuntu:~/xin/user2$ git tag -s -m "my first GPG-signed tag." mytag3
gpg: directory `/home/jagent/.gnupg' created
gpg: new configuration file `/home/jagent/.gnupg/gpg.conf' created
gpg: WARNING: options in `/home/jagent/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/home/jagent/.gnupg/secring.gpg' created
gpg: keyring `/home/jagent/.gnupg/pubring.gpg' created
gpg: skipped "user2 <user2@122.com>": secret key not available
gpg: signing failed: secret key not available
error: gpg failed to sign the data
error: unable to sign the tag
之所以签名失败,是因为找不到签名可用的公钥/私钥
jagent@ubuntu:~/xin/user2$ gpg --list-keys
gpg: /home/jagent/.gnupg/trustdb.gpg: trustdb created
jagent@ubuntu:~/xin/user2$ vim .git/config
jagent@ubuntu:~/xin/user2$ git tag -s -m "my first GPG-signed tag." mytag3 jagent@ubuntu:~/xin/user2$ git tag -l my* -n1
mytag blank commit.
mytag2 my first annotated tag
mytag3 my first GPG-signed tag.
jagent@ubuntu:~/xin/user2$ git cat-file tag mytag3
object af223af526008da109fe5b5b0d751d84ccead1c3
type commit
tag mytag3
tagger user2 <user2@122.com> 1605602353 +0800
my first GPG-signed tag.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQEcBAABAgAGBQJfs4wxAAoJEIcjcQwUdYeP+IcH/3kAw/xUzJNDUjFsl59rTzay
Vc5uCMyRbmFt68qHDSaCUhtYlEPVz8vNf0QqTVGRYgn6axPVmT5P+K/f+ypEs9nK
ytvfvYZIpO2ZA6RkbaN38UWD3Hs2H7IsACgarWB0BLhyx84ZAC8X9WQQcOa1QT2O
MPAv0NC/8RA+IOPLWHyOt1CQ+gnOiRxQ3mvArtMGnwNENBSMXQd7Zbb33NcAp8M1
8UV0YX20VIHgvdwDNW9L/r9ivTuE2DyELi66REUl5zgKHJV8Sf+Q3EcqaIT/4sxi
n4wFJEEkaGjquigYZhSnxEwbaqldWLoBoc6v24VVOCCQZZBfg+C5s0Azl45/v/s=
=p90+
-----END PGP SIGNATURE-----
jagent@ubuntu:~/xin/user2$ git tag -v mytag3
object af223af526008da109fe5b5b0d751d84ccead1c3
type commit
tag mytag3
tagger user2 <user2@122.com> 1605602353 +0800
my first GPG-signed tag.
gpg: Signature made Tue 17 Nov 2020 04:39:13 PM CST using RSA key ID 1475878F
gpg: Good signature from "user2 <user2@122.com>"
4.删除里程碑
git tag -d <tagname>
里程碑没有类似reflog的变更记录机制,一旦删除不易恢复,一旦发现删除,立即对里程碑进行重建
jagent@ubuntu:~/xin/user2$ git tag -n1
mytag blank commit.
mytag2 my first annotated tag
mytag3 my first GPG-signed tag.
jagent@ubuntu:~/xin/user2$ git tag -d mytag2
Deleted tag 'mytag2' (was 533070b)
jagent@ubuntu:~/xin/user2$ git tag mytag2 533070b
jagent@ubuntu:~/xin/user2$ git tag -n1
mytag blank commit.
mytag2 my first annotated tag
mytag3 my first GPG-signed tag.
5.不要随意更改里程碑
如果需要修改 需要添加-f或者--force参数强制覆盖已有的里程碑
6.共享里程碑(版本里程碑)
显示推送以配置库里程碑
git push origin <tagname>
推送本地所有的里程碑
git push origin refs/tags/*
可以用git ls-remote命令查看是否推送上去了
用户从版本库执行拉回操作,会自动获取里程碑
里程碑变更不能自动同步
当里程碑被强制更新。当里程碑被该更改后,已经获取里程碑的版本库再次使用获取或拉回操作,是不能自动更新里程碑。因为生成了不同的tag的对象
删除远程版本库的里程碑
本地删除 git tag -d <tagname>
远程删除 git push <remote_url>(origin) :<tagname>