Git标签与别名

Git标签与别名

1、Git标签

[root@localhost demo1]# cd /data/gitroot
[root@localhost gitroot]# git branch
  demo
  dev
* master
  test
  
  打一个标签v1.0
[root@localhost gitroot]# git tag v1.0 
   
查看标签信息
[root@localhost gitroot]# git show v1.0  
  
可以查看所有的标签
[root@localhost gitroot]# git tag     
v1.0

查看历史的commit
[root@localhost gitroot]# git log --pretty=oneline --abbrev-commit      
ea53299 ll
89b88e8 2.txt
4ab5058 gitroot.sh
ab5dc85 gitroor

针对历史commit打标签
[root@localhost gitroot]# git tag v0.9 89b88e8
[root@localhost gitroot]# git tag
v1.0
v0.9

可以对标签进行描述(”“内为描述的内容)
[root@localhost gitroot]# git tag -a v0.8 -m "test1" ab5dc85
[root@localhost gitroot]# git tag
v0.8
v0.9
v1.0
[root@localhost gitroot]# git show v0.8    查看标签信息

删除标签(-d为删除的意思)

[root@localhost gitroot]# git tag -d v0.8
[root@localhost gitroot]# git tag
v0.9
v1.0

推送指定标签到远程(可以在网页仓库上看到新的标签)

[root@localhost gitroot]# git push origin v1.0
Total 0 (delta 0), reused 0 (delta 0)
To git@github.com:lisikai1999/gitroot.git
 * [new tag]         v1.0 -> v1.0
[root@localhost gitroot]# git tag     查看标签
v0.9
v1.0
[root@localhost gitroot]# git tag v0.8 89b88e8
[root@localhost gitroot]# git tag
v0.8
v0.9
v1.0
[root@localhost gitroot]# git push --tag origin     推送所有标签
To git@github.com:lisikai1999/gitroot.git
 * [new tag]         v.08 -> v.08
 * [new tag]         v.09 -> v.09
[root@localhost gitroot]# git tag v1.0 -d    删除本地标签
[root@localhost gitroot]# git push origin :refs/tags/v1.0     删除远程标签

2、Git别名
创建别名

[root@localhost gitroot]# git config --global alias.ci commit
[root@localhost gitroot]# git config --global alias.co checkout
[root@localhost gitroot]# git config --global alias.br branch

查看git别名使用命令

[root@localhost gitroot]# git config --list |grep alias
alias.ci=commit
alias.co=checkout
alias.br=branch

列如:

[root@localhost gitroot]# git config --list |grep alias
[root@localhost gitroot]# git config --global alias.ci commit
[root@localhost gitroot]# git config --list |grep alias
alias.ci=commit
[root@localhost gitroot]# touch ls
[root@localhost gitroot]# git add ls
[root@localhost gitroot]# git ci -m "ls"
[root@localhost gitroot]# git log --pretty=oneline   --abbrev=commit
[root@localhost gitroot]# 

查询log小技巧

[root@localhost 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@localhost gitroot]# git config --list |grep alias
[root@localhost gitroot]# git lg
[root@localhost 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@localhost gitroot]# git config --global --unset alias.br 
[root@localhost gitroot]# git config --list |grep alias

GitLab的搭建与使用

服务端:
添加git用户,并且设置shell为/usr/bin/git-shell,目的是为了不让git用户远程登陆

[root@localhost ~]# useradd -s /usr/bin/git-shell git
[root@localhost ~]# cd /home/git

创建authorized_keys文件,并更改属主、属组和权限,用来存客户端机器上的公钥

[root@localhost git]# mkdir .ssh
[root@localhost git]# cd .ssh/
[root@localhost .ssh]# touch authorized_keys
[root@localhost .ssh]# cd..
[root@localhost git]# chown -R git.git .ssh
[root@localhost git]# chmod 600 .ssh/authorized_keys
[root@localhost git]# ll /home/git/.ssh/authorized_keys 
-rw-------. 1 git git 1226 Aug  5 07:03 /home/git/.ssh/authorized_keys

定好存储Git仓库的目录

[root@localhost git]# mkdir /data/gitpub
[root@localhost git]# cd /data/gitpub

创建一个裸仓库 (裸仓库没有工作区,因为服务器上的Git仓库纯粹是为了共享,所以不让用户直接登录到服务器上去改工作区,并且服务器上的Git仓库通常都以.git结尾)

[root@localhost gitpub]# git init --bare sample.git
Initialized empty Git repository in /opt/kkk/test.git/
[root@localhost gitpub]# chown -R git.git sample.git
[root@localhost gitpub]# ll
total 4
drwxr-xr-x. 7 git git 4096 Aug  5 10:01 sample.git

客户端:

[root@localhost ~]# cat .ssh/id_rsa.pub

服务端:

[root@localhost gitpub]# cd /home/git
[root@localhost git]# vi .ssh/authorized_keys     把复制的密钥粘贴过来 
[root@localhost git]# systemctl stop firewalld  

客户端:

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# git clone git@192.168.200.10:/data/gitpub/sample.git
[root@localhost ~]# ls
anaconda-ks.cfg  dump.rdb  sample
[root@localhost ~]# ls /opt/
myproject
[root@localhost ~]# cd /opt/
[root@localhost opt]# git clone git@192.168.200.10:/data/gitpub/sample.git
[root@localhost opt]# ls
myproject  sample
[root@localhost opt]# cd sample/
[root@localhost sample]# ll -a
total 4
drwxr-xr-x. 3 root root   17 Nov  6 22:30 .
drwxr-xr-x. 4 root root   34 Nov  6 22:07 ..
drwxr-xr-x. 8 root root 4096 Nov  6 22:26 .git

GitLab的使用

[root@localhost ~]#  vi /etc/yum.repos.d/gitlab.repo
[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1
[root@localhost ~]# yum clean all
[root@localhost ~]# yum repolist
[root@localhost ~]# yum install -y gitlab-ce
[root@localhost ~]# netstat -lnpt  //查看监听端口
[root@localhost ~]# gitlab-ctl status

浏览器访问GitLab,输入IP即可

GitLab备份

[root@localhost ~]# gitlab-rake gitlab:backup:create    创建备份压缩包(需要多等会儿)

备份目录在/var/opt/gitlab/backups

[root@localhost ~]# ls /var/opt/gitlab/backups/
1596633046_2020_08_05_13.2.2_gitlab_backup.tar

GitLab恢复,需要先停服务

[root@localhost ~]# gitlab-ctl stop unicorn ; gitlab-ctl stop sidekiq
ok: down: sidekiq: 0s, normally up

恢复备份(编号,即备份文件的前缀)

[root@localhost ~]#gitlab-rake gitlab:backup:restore BACKUP=1596633046_2020_08_05_13.2.2 

再启动服务

[root@localhost ~]# gitlab-ctl start 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值