前提:查看分支
[root@fengxi ~]# cd /data/gitroot/
[root@fengxi gitroot]# git branch
demo
dev
* master
1.标签
(1)打标签
[root@fengxi gitroot]# git tag v1.0
(2)查看标签信息
[root@fengxi gitroot]# git show v1.0
commit 5844aa0301980969dc83608a2d4e89b69e17b191
Merge: 28ef615 c37502b
Author: lsk <example@qq.com>
Date: Tue Nov 10 05:28:57 2020 +0800
2.txt
(3)查看所有标签信息
[root@fengxi gitroot]# git tag
v1.0
(4)查看历史的commit(tag是针对commit来打标签的,所以可以针对历史的commit来打tag)
[root@fengxi gitroot]# git log --pretty=oneline --abbrev-commit
5844aa0 2.txt
28ef615 2.txt
c37502b 2.txt
e7265d4 new file 2.txt
45af9a3 rm 2.txt
5fd2812 new file 2.txt
97014b9 1.txt chang 1
d774da8 1.txt chang 1
0ddbb51 add new file 1.txt
(5)历史commit打标签
[root@fengxi gitroot]# git tag v0.9 28ef615
(6)查看标签(可以看到多了一个v0.9)
[root@fengxi gitroot]# git tag
v0.9
v1.0
(7)对标签进行描述
[root@fengxi gitroot]# git tag -a v0.8 -m "dvjbis" c37502b
查看标签
[root@fengxi gitroot]# git tag
v0.8
v0.9
v1.0
查看v0.8的标签
[root@fengxi gitroot]# git show v0.8
tag v0.8
Tagger: lsk <example@qq.com>
Date: Tue Nov 10 06:20:11 2020 +0800
dvjbis
commit c37502ba4afb166a78e44554db3b8541363d0e6d
Author: lsk <example@qq.com>
Date: Tue Nov 10 05:22:45 2020 +0800
2.txt
diff --git a/2.txt b/2.txt
index 5455d64..2ba740d 100644
--- a/2.txt
+++ b/2.txt
@@ -1 +1,3 @@
guojian
+2
+1
(8)删除标签
[root@fengxi gitroot]# git tag -d v0.8
Deleted tag 'v0.8' (was 8ea2a8e)
查看标签
[root@fengxi gitroot]# git tag
v0.9
v1.0
(9)推送标签
先看一下网站上的标签
在CRT上进行推送
[root@fengxi gitroot]# git push origin v1.0
Total 0 (delta 0), reused 0 (delta 0)
To git@github.com:guo-xia-bub/demo-1.git
* [new tag] v1.0 -> v1.0
进行查看
推送所有标签
[root@fengxi gitroot]# git tag v0.8 45af9a3
[root@fengxi gitroot]# git tag
v0.8
v0.9
v1.0
[root@fengxi gitroot]# git push --tag origin
Total 0 (delta 0), reused 0 (delta 0)
To git@github.com:guo-xia-bub/demo-1.git
* [new tag] v0.8 -> v0.8
* [new tag] v0.9 -> v0.9
(10)删除本地标签
[root@fengxi gitroot]# git tag -d v1.0
Deleted tag 'v1.0' (was 5844aa0)
(11)删除远程标签
[root@fengxi gitroot]# git push origin :refs/tags/v1.0
To git@github.com:guo-xia-bub/demo-1.git
- [deleted] v1.0
2.git别名(使用别名可以提高我们的工作效率)
(1)查询系统自带别名
[root@fengxi gitroot]# git config --list|grep alias
(2)设置别名
[root@fengxi gitroot]# git config --global alias.ci commit
[root@fengxi gitroot]# git config --global alias.co checkout
[root@fengxi gitroot]# git config --global alias.br branch
[root@fengxi gitroot]# git config --list|grep alias
alias.ci=commit
alias.co=checkout
alias.br=branch
(3)别名的使用
[root@fengxi gitroot]# touch ls
[root@fengxi gitroot]# git add ls
[root@fengxi gitroot]# git ci -m"ls"
[master 214920b] ls
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 ls
取消别名
[root@fengxi gitroot]# git config --global --unset alias.ci
取消后查看
[root@fengxi gitroot]# git config --list|grep alias
alias.co=checkout
alias.br=branch
3.查询log的小技巧
[root@fengxi gitroot]# git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
[root@fengxi gitroot]# git config --list|grep alias
alias.co=checkout
alias.br=branch
alias.lg=log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
运行一下上面的命令:
[root@fengxi gitroot]# git lg
* 214920b - (HEAD, master) ls (30 minutes ago) <lsk>
* 5844aa0 - (origin/dev, dev, demo) 2.txt (2 hours ago) <lsk>
|\
| * c37502b - 2.txt (2 hours ago) <lsk>
* | 28ef615 - (tag: v0.9) 2.txt (2 hours ago) <lsk>
|/
* e7265d4 - new file 2.txt (2 hours ago) <lsk>
* 45af9a3 - (tag: v0.8, origin/master) rm 2.txt (4 hours ago) <ls
* 5fd2812 - new file 2.txt (4 hours ago) <lsk>
* 97014b9 - 1.txt chang 1 (5 hours ago) <lsk>
* d774da8 - 1.txt chang 1 (5 hours ago) <lsk>
* 0ddbb51 - add new file 1.txt (5 hours ago) <lsk>
取消别名
[root@fengxi gitroot]# git config --global --unset alias.ci