gitlab&&jenkins

安裝和配置git

[root@k8s-node2 ~]# yum install git -y
[root@k8s-node2 ~]# git --version 
git version 1.8.3.1

git config --global user.name "lcx"
git config --global user.email "245684979@qq.com"
git config --global color.ui   "true"

創(chuàng)建版本庫(kù)

git init 

git倉(cāng)庫(kù)添加文件

git add .  #添加文件到緩沖區(qū)
git commit -m 'ad three file'

git 修改文件名稱并提交

git mv file1 file4
git commit -m 'change file name'

git的文件對(duì)比

git diff file3   #本地目錄和緩沖去文件對(duì)比
git diff --cached file3   #緩沖區(qū)文件和倉(cāng)庫(kù)文件對(duì)比

image
image

實(shí)現(xiàn)回退功能

image
[root@k8s-node2 ~]# git log --oneline 
58bea1a add three file
fe9e8c2 add two file
[root@k8s-node2 ~]# cat file2
456456456
8888888
[root@k8s-node2 ~]# git reset --hard 58bea1a
HEAD is now at 58bea1a add three file
[root@k8s-node2 ~]# cat file2
456456456

#查看所有歷史版本
[root@k8s-node2 ~]# git reflog --oneline
fe9e8c2 HEAD@{0}: reset: moving to fe9e8c2
58bea1a HEAD@{1}: commit: add three file
fe9e8c2 HEAD@{2}: commit (initial): add two file

[root@k8s-node2 ~]# git reset --hard 58bea1a

image

撤回

[root@k8s-node2 ~]# echo 8888888 > file2 
[root@k8s-node2 ~]# git diff  file2
diff --git a/file2 b/file2
index 7d7a948..80f456a 100644
--- a/file2
+++ b/file2
@@ -1 +1 @@
-456456456
+8888888
[root@k8s-node2 ~]# git checkout file2
[root@k8s-node2 ~]# git diff  file2
[root@k8s-node2 ~]# cat file2 
456456456

撤銷修改的文件

提交到緩沖區(qū)的文件撤回
git reset HEAD file2

未add到緩沖區(qū)的文件撤回
git checkout -- file2

git分支管理

#查看分支
git branch    ----> * master

#增加一個(gè)新分支
git branch dev01

#切換分支
git checkout dev01

#合并分支
git merge master

#在開(kāi)發(fā)分支上合并主分支
git  merge master -m '注釋'

#切回主分支
git checkout master

#在主分支次合并開(kāi)發(fā)分支
git merge dev01 -m '注釋'

git標(biāo)簽管理

標(biāo)簽就是給commit起一個(gè)別名,容易記憶

#添加標(biāo)簽
git log --oneline 
git tag v1.2    ----> 給當(dāng)前版本打標(biāo)簽
git tag -a v1.0 -m '注釋,優(yōu)化了修復(fù)了什么' <commit的ID>

#刪除標(biāo)簽
git tag -d v1.2

[root@k8s-node2 demo]# git log --oneline 
b8e21cc add test.txt
9d5ab15 add test.txt
382f080 add test.txt
ff6047d add file6 file7
b693580 add file6 file7
58bea1a add three file
fe9e8c2 add two file
[root@k8s-node2 demo]# git tag 
[root@k8s-node2 demo]# git tag v1.2 
[root@k8s-node2 demo]# git tag 
v1.2
[root@k8s-node2 demo]# git show v1.2 
commit b8e21cc519dfd918ee880831e37585afcdf73410
Author: oldqiang <296917342@qq.com>
Date:   Mon Sep 23 12:03:35 2019 +0800

    add test.txt

diff --git a/demo/test.txt b/demo/test.txt
index 69f66d3..d99f9f0 100644
--- a/demo/test.txt
+++ b/demo/test.txt
@@ -1,3 +1,3 @@
 11111
-aaaaa
+22222
 33333
[root@k8s-node2 demo]# git tag -a v1.0 -m 'v1.0 add 后裔' fe9e8c2
[root@k8s-node2 demo]# git tag 
v1.0
v1.2
[root@k8s-node2 demo]# git show v1.0
tag v1.0
Tagger: oldqiang <296917342@qq.com>
Date:   Mon Sep 23 12:18:45 2019 +0800

v1.0 add 后裔

commit fe9e8c25cfb61eb63da6681dc09d054cd5739243
Author: oldqiang <296917342@qq.com>
Date:   Mon Sep 23 10:44:54 2019 +0800

    add two file

diff --git a/file1 b/file1
new file mode 100644
index 0000000..5721413
--- /dev/null
+++ b/file1
@@ -0,0 +1 @@
+423

擴(kuò)展
Git 打補(bǔ)丁-- patch 和 diff 的使用
diff
patch 打補(bǔ)丁,創(chuàng)建補(bǔ)丁,卸載補(bǔ)丁

git克隆 碼云網(wǎng)站復(fù)制項(xiàng)目鏈接

image

git遠(yuǎn)程倉(cāng)庫(kù)gitee

image.png
image.png
ssh-keygen -t rsa
cat /root/.ssh/id_rsa.pub 
cd /root/demo/
ll
git remote add origin git@gitee.com:linuxcx/linux.git
git push -u origin master

gitlab安裝

#上傳gitlab-ce-11.9.11-ce.0.el7.x86_64.rpm到當(dāng)前目錄

echo "192.168.37.202  mirrors.aliyun.com" >>/etc/hosts
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum localinstall gitlab-ce-11.9.11-ce.0.el7.x86_64.rpm -y

vim  /etc/gitlab/gitlab.rb
#設(shè)置訪問(wèn)url和關(guān)閉prometheus
external_url 'http://http://gitlablcx.com'
prometheus_monitoring['enable'] = false

#配置gitlab通過(guò)smtp發(fā)送郵件
[root@k8s-node2 demo]# vim /etc/gitlab/gitlab.rb 
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = '245684979@qq.com'
gitlab_rails['gitlab_email_display_name'] = 'linux_gitlab'

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "245684979"
gitlab_rails['smtp_password'] = "lvlina.199625"
gitlab_rails['smtp_domain'] = "qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true

#重新配置
gitlab-ctl reconfigure

gitlab漢化

image.png
#下載漢化包
https://gitlab.com/xhang/gitlab

gitlab-ctl stop
tar xf gitlab-11-9-stable-zh.tar.gz
\cp -a gitlab-11-9-stable-zh/* /opt/gitlab/embedded/service/gitlab-rails/

image.png

gitlab-用戶-用戶組-項(xiàng)目之間的關(guān)系

先創(chuàng)建用戶組,在基于用戶組創(chuàng)建項(xiàng)目,最后創(chuàng)建用戶,編輯用戶組,添加成員,注意權(quán)限

image

gitlab備份和恢復(fù)

#備份
gitlab-rake gitlab:backup:create

#恢復(fù)
gitlab-ctl stop
gitlab-rake gitlab:backuip:restore BACKUP=1510472027_2019_09_23_9.4.5
gitlab-ctl start

vim /etc/gitlab/gitlab.rb
gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
gitlab_rails['backup_keep_time'] = 604800

#遷移云主機(jī)
先備份,云主機(jī)安裝相同版本,恢復(fù)

#更新配置
gitlab-ctl reconfigure

gitlab版本升級(jí)

gitlab升級(jí),要小版本跨   10--->11--->12

擴(kuò)展內(nèi)容:

1.安裝svn服務(wù)器,將svn中的數(shù)據(jù)遷移到git倉(cāng)庫(kù)
git-svn
git clone svn

svn是一個(gè)中心化的版本控制工具,git是分布式的,每個(gè)人都可以有完整的代碼倉(cāng)庫(kù)

2.找回gitlab的root密碼

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
禁止轉(zhuǎn)載,如需轉(zhuǎn)載請(qǐng)通過(guò)簡(jiǎn)信或評(píng)論聯(lián)系作者。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容