首页 > 其他分享 >git-jenkins阶段02 git标签, github使用, gitlab安装, 配置, 使用, 开发推送和克隆代码

git-jenkins阶段02 git标签, github使用, gitlab安装, 配置, 使用, 开发推送和克隆代码

时间:2024-06-11 15:14:29浏览次数:9  
标签:02 git -- data gitlab Jun root

1.Git的标签

-a        指定标签的名字
-m        指定说明信息

[root@git git_data]# git log --oneline
7d9c037 modify ccc.txt 1
3f8051e commit modify oldboy.txt
c22a40f modify test

#把某一次的提交作为一次标签
[root@git git_data]# git tag -a v2.0 7d9c037 -m "test" #tag -a打标签名称  -m做备注
[root@git git_data]# git tag    #显示所有标签
v1.0
v2.0
[root@git git_data]# git show v2.0    #查看标签内容
tag v2.0
Tagger: qls <[email protected]>
Date:   Mon Jun 10 08:54:54 2024 +0800
test

commit 7d9c0374ff90dfbb0b6f5b7b7001b6b802d1e172
Author: qls <[email protected]>
Date:   Mon Jun 10 08:53:21 2024 +0800

    modify ccc.txt 1

diff --git a/ccc.txt b/ccc.txt
new file mode 100644
index 0000000..90d2950
--- /dev/null
+++ b/ccc.txt
@@ -0,0 +1 @@
+111111

#将数据恢复到某个标签
[root@git git_data]# git reset --hard v2.0
HEAD is now at 7d9c037 modify ccc.txt 1
[root@git git_data]# ll
total 8
-rw-r--r-- 1 root root  0 Jun  7 02:57 aaa.txt
-rw-r--r-- 1 root root  0 Jun  7 02:57 bbb.txt
-rw-r--r-- 1 root root  7 Jun 10 19:59 ccc.txt
-rw-r--r-- 1 root root  0 Jun  7 21:45 master.txt
-rw-r--r-- 1 root root 32 Jun  7 23:17 oldboy.txt
-rw-r--r-- 1 root root  0 Jun  7 21:40 test.txt
[root@git git_data]# cat ccc.txt 
111111

#删除标签
[root@git git_data]# git tag -d v1.0
Deleted tag 'v1.0' (was ccd9800)

2.Github的使用

git版本库的托管

1.注册好用户

创建仓库

#查看本地仓库的远程仓库
[root@git git_data]# git remote

#添加一个远程仓库,这里选择秘钥的方式
[root@git git_data]# git remote add origin [email protected]:DingchaoLu-cloud/git_data.git
[root@git git_data]# git remote
origin

#将本地仓库数据推送到远程仓库失败
[root@git git_data]# git push -u origin main
Warning: Permanently added 'github.com,20.205.243.166' (ECDSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

#删除原来的秘钥,重新创建(第一次创建不需要执行)
[root@git .ssh]# rm -rf /root/.ssh/
#创建密钥对
[root@git git_data]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:IItiiPSz2HneC8epkIV8cvM2rhq5SEahewArw8n0tz8 root@git
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|                 |
|.+  . .          |
|X.*..o .         |
|X*.B.*  S        |
|+=o % = .        |
|.+.O + B         |
|o.. * OE.        |
| . o.+.=o        |
+----[SHA256]-----+
#查看公钥信息,复制公钥,粘贴到web界面
[root@git ~]# cat .ssh/id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABA... root@git

github配上SSH keys, 把公钥复制进去

点setting

#再次推送数据
[root@git git_data]# git push -u origin master
Counting objects: 30, done.
Compressing objects: 100% (23/23), done.
Writing objects: 100% (30/30), 2.25 KiB | 0 bytes/s, done.
Total 30 (delta 10), reused 0 (delta 0)
remote: Resolving deltas: 100% (10/10), done.
remote: To [email protected]:DingchaoLu-cloud/git_data.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

#克隆远程仓库到本地
#注意:下载别人的项目不能用SSH,因为没有别人仓库的公钥,没法下载
[root@git git_data]# cd /opt/
[root@git opt]# git clone [email protected]:DingchaoLu-cloud/git_data.git    #这里下载自己仓库,用SSH下载
Cloning into 'git_data'...
remote: Enumerating objects: 30, done.
remote: Counting objects: 100% (30/30), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 30 (delta 10), reused 30 (delta 10), pack-reused 0
Receiving objects: 100% (30/30), done.
Resolving deltas: 100% (10/10), done.

3.Gitlab安装

清华源镜像
https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
gitlab官方网站
https://about.gitlab.com/

官网选择安装,手动安装,centos版本,选ce社区版,ee是企业版,如图, 查看安装包

 https://packages.gitlab.com/gitlab/gitlab-ce

环境
2G内存    50G磁盘
企业    >4G内存
安装包:    gitlab-ce-10.2.2
禁用防火墙和selinux

#1. 上传安装包
[root@git ~]# rz
gitlab-ce-10.2.2-ce.0.el7.x86_64.rpm

#安装 出现报错,缺少依赖
[root@git ~]# rpm -ivh gitlab-ce-10.2.2-ce.0.el7.x86_64.rpm
warning: gitlab-ce-10.2.2-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
error: Failed dependencies:
    policycoreutils-python is needed by gitlab-ce-10.2.2-ce.0.el7.x86_64
#安装依赖
[root@git ~]# yum install -y policycoreutils-python

#再次安装,安装成功
[root@git ~]# rpm -ivh gitlab-ce-10.2.2-ce.0.el7.x86_64.rpm
warning: gitlab-ce-10.2.2-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:gitlab-ce-10.2.2-ce.0.el7        ################################# [100%]
It looks like GitLab has not been configured yet; skipping the upgrade script.

       *.                  *.
      ***                 ***
     *****               *****
    .******             *******
    ********            ********
   ,,,,,,,,,***********,,,,,,,,,
  ,,,,,,,,,,,*********,,,,,,,,,,,
  .,,,,,,,,,,,*******,,,,,,,,,,,,
      ,,,,,,,,,*****,,,,,,,,,.
         ,,,,,,,****,,,,,,
            .,,,***,,,,
                ,*,.
  


     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ \`/ __ \
  / /_/ / / /_/ /___/ /_/ / /_/ /
  \____/_/\__/_____/\__,_/_.___/
  

Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting `external_url`
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
  sudo gitlab-ctl reconfigure

For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md


#gitlab相关文件及目录介绍
[root@git ~]# ll /etc/gitlab/gitlab.rb         #主配置文件

[root@git ~]# cd /opt/gitlab/        #安装程序目录

[root@git gitlab]# ll /var/opt/        #数据存放目录

#修改配置文件,地址改成要访问的地址(需要重新加载才会生效)
[root@git gitlab]# vim /etc/gitlab/gitlab.rb
external_url 'http://10.0.0.81'

#重新加载配置文件
[root@git gitlab]# gitlab-ctl reconfigure

#gitlab的状态(查看各种服务运行状态)
[root@git gitlab]# gitlab-ctl status
run: gitaly: (pid 9098) 22s; run: log: (pid 8796) 69s
run: gitlab-monitor: (pid 9116) 22s; run: log: (pid 8895) 57s    #监控模式
run: gitlab-workhorse: (pid 9087) 23s; run: log: (pid 8751) 82s    #反向代理服务
run: logrotate: (pid 8779) 75s; run: log: (pid 8778) 75s        #日志
run: nginx: (pid 8758) 81s; run: log: (pid 8757) 81s            #web界面
run: node-exporter: (pid 8845) 63s; run: log: (pid 8844) 63s
run: postgres-exporter: (pid 9142) 21s; run: log: (pid 9025) 39s
run: postgresql: (pid 8526) 131s; run: log: (pid 8525) 131s        #数据库
run: prometheus: (pid 9132) 21s; run: log: (pid 8927) 45s        #监控
run: redis: (pid 8466) 137s; run: log: (pid 8465) 137s            #缓存数据库
run: redis-exporter: (pid 8912) 51s; run: log: (pid 8911) 51s
run: sidekiq: (pid 8735) 89s; run: log: (pid 8734) 89s            #后台执行队列任务
run: unicorn: (pid 8696) 95s; run: log: (pid 8695) 95s            #动态的web程序

#gitlab管理命令
gitlab-ctl        start        stop        restart
#单独停掉其中某个服务
gitlab-ctl stop nginx

#查看gitlab所有服务日志
[root@git gitlab]# gitlab-ctl tail

#查看每个服务单独的日志
[root@git gitlab]# ll /var/log/gitlab
total 0
drwx------ 2 git               root        47 Jun 10 23:50 gitaly
drwx------ 2 git               root        47 Jun 10 23:50 gitlab-monitor
drwx------ 2 git               root       188 Jun 10 23:49 gitlab-rails
drwx------ 2 git               root        30 Jun 10 23:49 gitlab-shell
drwx------ 2 git               root        47 Jun 10 23:50 gitlab-workhorse
drwx------ 2 root              root        47 Jun 10 23:50 logrotate
drwxr-x--- 2 root              gitlab-www 131 Jun 10 23:50 nginx
drwx------ 2 gitlab-prometheus root        47 Jun 10 23:50 node-exporter
drwx------ 2 gitlab-psql       root        47 Jun 10 23:50 postgres-exporter
drwx------ 2 gitlab-psql       root        47 Jun 10 23:49 postgresql
drwx------ 2 gitlab-prometheus root        47 Jun 10 23:50 prometheus
drwxr-xr-x 2 root              root        28 Jun 10 23:49 reconfigure
drwx------ 2 gitlab-redis      root        47 Jun 10 23:49 redis
drwx------ 2 gitlab-redis      root        47 Jun 10 23:50 redis-exporter
drwx------ 2 git               root        47 Jun 10 23:50 sidekiq
drwx------ 2 git               root        99 Jun 10 23:50 unicorn

#web界面进行访问
http://10.0.0.81/
#输入root注册密码12345678
用户:root
密码:12345678
#进行登录

 修改登录页面外观,点击扳手,如图

 设置外观,如图

 退出重新登录,如图

#关闭注册功能  
#(公司人不多,可以关闭)

如图,点击扳手,点击setting

 注意 Sign-in 登录千万不要关闭,否则无法登录

点击save,然后退出。在进入登录界面,如图,没有注册选项了

创建组

创建用户 qls

如图,其他地方不动,普通用户Regular,点击Create user创建

 如图,点击edit,进入修改密码12345678

就可以用新创建的qls用户登录,重置密码(可以和原密码一致)

#把用户添加到组里
重新用root登录,点击扳手,组名,点击Add users to group把用户添加到组里
Guest和Reportor几乎没有权限,一般给Developer,如果领导可以给Master权限

 

创建项目

#注意,下图中项目组一定要改所在项目组, 如这里的OPS;如果初始的root,OPS项目组的人无法查看

项目创建完成后,点击上方黄色提醒,添加SSH公钥
#这个SSH公钥是针对当前用户的公钥,并不是单单这个项目的公钥。
#刚刚创建qls用户,也只要上传自己的公钥即可管理项目

#获取机器的公钥
[root@git ~]# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3N...Ropsf root@git

复制服务器上的公钥,如图

#提交代码到gitlab上

#先移除之前github的远程仓库
[root@git git_data]# git remote
origin
[root@git git_data]# git remote remove origin #移除远程仓库
[root@git git_data]# git remote

#添加gitlab远程仓库
[root@git git_data]# git remote add origin [email protected]:OPS/git_data.git
[root@git git_data]# git remote
origin

#把本地代码推送到远程仓库
[root@git git_data]# git push -u origin master

#修改源代码,之后再推送到gitlab上面
[root@git git_data]# echo "test" >> ddd.txt    #创建ddd.txt文件
[root@git git_data]# git add .
[root@git git_data]# git commit -m "new file add.txt"
[master a448a5e] new file add.txt
 1 file changed, 1 insertion(+)
 create mode 100644 ddd.txt
 #-u选择哪一个远程仓库
[root@git git_data]# git push -u origin master
Counting objects: 4, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 260 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To [email protected]:OPS/git_data.git
   7d9c037..a448a5e  master -> master
Branch master set up to track remote branch master from origin.


#开发人员推送代码到gitlab

1.创建一个开发用户,让其加入OPS组,拥有上传和下载代码的权限
#创建一个开发用户dev01,密码12345678,把他添加到OPS项目组,Developer权限
#用dev01账号登录

2.克隆一台新的服务器
#创建dev01-10.0.0.82环境(模拟开发环境)
[root@dev01 ~]# yum install -y git
#创建密钥对
[root@dev01 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:Hf+Vr3ZvMNc2SSKy+8s5bS79+IhRDIj2OofPtT/ozfo root@dev01
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|        . .      |
|       o ...     |
|      . .o +o. ..|
|        S.+ ooo.+|
|        o.  ..o+=|
|       + ..o+ .=o|
|        =.o+B=+.o|
|         ooXXE==o|
+----[SHA256]-----+
[root@dev01 ~]# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc...5l85N root@dev01
#把公钥添加到gitlab下dev01用户对应的SSH Keys

#把gitlab上的项目下载到本地
[root@dev01 ~]# git clone [email protected]:OPS/git_data.git
Cloning into 'git_data'...
The authenticity of host '10.0.0.81 (10.0.0.81)' can't be established.
ECDSA key fingerprint is SHA256:2SQdzwgUOhQNWwPZEZSV9NaJ2i3tS2GgUaCazKOyOew.
ECDSA key fingerprint is MD5:24:68:a9:38:f3:00:b4:7b:8a:72:0f:2a:c9:77:82:e0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.81' (ECDSA) to the list of known hosts.
remote: Counting objects: 33, done.
remote: Compressing objects: 100% (25/25), done.
remote: Total 33 (delta 11), reused 0 (delta 0)
Receiving objects: 100% (33/33), done.
Resolving deltas: 100% (11/11), done.
[root@dev01 ~]# ll
total 8
-rw-------. 1 root root 1457 Jun 14  2023 anaconda-ks.cfg
drwxr-xr-x  3 root root  130 Jun 11 22:27 git_data
-rw-r--r--  1 root root  131 Jun 15  2023 host.sh

#提交代码
[root@dev01 git_data]# echo "test" >> dev01.txt
[root@dev01 git_data]# git add .
#提交报错,因为没有配置用户和邮箱
[root@dev01 git_data]# git commit -m "new file dev01.txt"
*** Please tell me who you are.
Run
  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'root@dev01.(none)')
#设置用户和邮箱
[root@dev01 git_data]# git config --global user.name dev01
[root@dev01 git_data]# git config --global user.email [email protected]
[root@dev01 git_data]# git commit -m "new file dev01.txt"
[master 028f59a] new file dev01.txt
 1 file changed, 1 insertion(+)
 create mode 100644 dev01.txt
#上传到远端仓库
[root@dev01 git_data]# git push -u origin master
Counting objects: 3, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 222 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
To [email protected]:OPS/git_data.git
   a448a5e..028f59a  master -> master
Branch master set up to track remote branch master from origin.


#10.0.0.81环境同步数据,把原项目删了,重新拉取最新的代码
[root@git ~]# rm -rf git_data/
[root@git ~]# git clone [email protected]:OPS/git_data.git
Cloning into 'git_data'...
remote: Counting objects: 35, done.
remote: Compressing objects: 100% (27/27), done.
remote: Total 35 (delta 12), reused 0 (delta 0)
Receiving objects: 100% (35/35), done.
Resolving deltas: 100% (12/12), done.
[root@git ~]# cd git_data/
[root@git git_data]# ll
total 16
-rw-r--r-- 1 root root  0 Jun 11 21:37 aaa.txt
-rw-r--r-- 1 root root  0 Jun 11 21:37 bbb.txt
-rw-r--r-- 1 root root  7 Jun 11 21:37 ccc.txt
-rw-r--r-- 1 root root  5 Jun 11 21:37 ddd.txt
-rw-r--r-- 1 root root  5 Jun 11 21:37 dev01.txt
-rw-r--r-- 1 root root  0 Jun 11 21:37 master.txt
-rw-r--r-- 1 root root 32 Jun 11 21:37 oldboy.txt
-rw-r--r-- 1 root root  0 Jun 11 21:37 test.txt

 

标签:02,git,--,data,gitlab,Jun,root
From: https://www.cnblogs.com/ludingchao/p/18242050

相关文章

  • 2024最新国产免费AI工具合集
    【导读】谁还在说国产AI不好用?今天就给大家分享几款2024年最新出品的免费又好用的国产AI工具集吧。一、阿里通义万相这是阿里出品的一款免费的AI绘图工具。你可以轻松制作自己想要的插画或海报,对于需要处理大量图片的设计师、摄影师或电商从业者来说,这款工具无疑能大大提升工......
  • docker镜像源挂了后操作2024-6-6
    @目录概要解决方案小结概要端午前6.6号不是docker所有的加速器都关了嘛,这回做了些功课,了解了下讨论背景,原来想直接走代理这个方案的,但是我买的都是订阅制的,不好搞前后研究最后还是找阿里云官方给了解决方案。解决方案看官网文档sudomkdir-p/etc/dockersudotee/etc/dock......
  • 2024年声波清洗机选购指南!声波清洗器有必要买吗?哪个牌子好?
    随着电子产品的普及,越来越多的年轻人开始佩戴眼镜!但是眼镜的清洁问题却常常被忽视,直到污渍和灰尘影响了我们的视觉体验和眼镜的美观。传统的清洗方法往往无法彻底清除眼镜上的顽固污渍,而眼镜超声波清洗机的出现无疑解决了眼镜佩戴者的苦恼!超声波清洗技术利用高频振动产生的微......
  • 618超声波清洗机怎么选?精选2024年好用的声波清洗器,错过后悔
    眼镜作为我们日常生活中不可或缺的辅助工具,其清洁和保养显得尤为重要。传统的清洗方法往往费时费力,且难以彻底清除眼镜上的污渍和细菌。因此,超声波眼镜清洗机应运而生,它以其高效、便捷、彻底的清洗效果,迅速成为眼镜护理的新宠。超声波眼镜清洗机利用超声波技术,通过高频振动产生......
  • pgAdmin未授权命令执行漏洞(CVE-2022-4223)
    ​https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v5.7/source/pgadmin4-5.7.tar.gz 下载pgadmin5.7的源码首先从代码层面进行分析接口 /validate_binary_path​最后调用了 subprocess.getoutput(​来执行了命令这一部分代码是对传入的路径进行检测,如果是在linu......
  • Adobe Premiere Pro 2024下载安装(视频剪辑软件Pr2024)
    百度网盘下载地址(含PR教学课程(PR从入门到精通108节课程))https://pan.baidu.com/s/1WKYZENoMzTcKhbgMgbEPGQ?pwd=SIMS一、Pr简介Pr全称Premiere,是Adobe公司开发的一款功能强大的视频剪辑软件,目前被广泛应用于抖音、快手以及火山小视频等。AdobePremierePro2024是一款专业的......
  • 0026-删除有序数组中的重复项
    26.删除有序数组中的重复项给你一个非严格递增排列的数组nums,请你原地删除重复出现的元素,使每个元素只出现一次,返回删除后数组的新长度。元素的相对顺序应该保持一致。然后返回nums中唯一元素的个数。考虑nums的唯一元素的数量为k,你需要做以下事情确保你的题......
  • git 教程:如何从github上拉取项目 · 进行修改并上传到自己仓库 · 一个仓库保存,多端同
    一:删除原始的远程仓库链接首先,查看当前的远程仓库链接:gitremote-v你会看到类似如下的输出:originhttps://github.com/othersusername/others-project.git(fetch)originhttps://github.com/othersusername/others-project.git(push)删除原始远程仓库链接:git......
  • [ToneTuneToolkit][023]UGUI的去色,使UI元素变为灰色
    #regionEnvironmentWindows1022H2Unity2022.3.30f1LTSVSCode1.90.0//ToneTuneToolkit下载地址// https://github.com/MirzkisD1Ex0/ToneTuneToolkit.git#endregion 把UGUI的元素去色!变成灰色!!!超级方便!//该项功能已包含至ToneTuneToolkit插件  01.新建场景,新建......
  • 《DX12龙书》-第一个例程出现的报错:error: 应用程序请求的操作依赖于已缺失或不匹配的
    《DX12龙书》|《Introductionto3DGameProgrammingwithDirectX12》|《DirectX123D游戏开发实践》个人电脑环境Window11;VisualStudio2022出现问题主要原因:书中代码的环境是:Windows10;VS2015,在不同环境上运行难免会出现一些错误。问题一:C2102&要求左值错......