代碼管理平臺

第三十七課 代碼管理平臺html

目錄node

1、代碼管理平臺介紹
2、安裝svn
3、客戶端上使用svn(linux)
4、客戶端上使用svn(windows)
5、單機上使用git
6、簡歷遠程倉庫
7、克隆遠程倉庫
8、分支管理
9、遠程分支管理
10、標籤管理
11、git別名
12、搭建git服務器
十3、安裝gitlab
十4、使用gitlab
十5、gitlab備份和恢復
十6、擴展python


1、代碼管理平臺介紹

軟件的版本控制(Revision control)是一種軟件工程技巧,藉此能在軟件開發的過程當中,確保由不一樣人所編輯的同一代碼文件案都獲得同步。軟件設計師常會利用版本控制來追蹤、維護源碼、文件以及配置文件等等的改動,而且提供控制這些改動控制權的程序。linux

版本管理工具發展簡史,cvs→svn→git 更詳細信息可參考http://luckypoem14.github.io/test/2012/04/24/scm-history/nginx

SVN全稱subversion,是一個開源版本控制系統,始於2000年git

git是linux創始人linus發起的,2005年發佈,最初目的是更好管理linux內核代碼github

git和svn不一樣在於git不須要依賴服務端就能夠工做,即git是分佈式的web

關於git和svn的比較你們參考http://blog.lishiming.net/?p=305redis

github是基於git的在線web頁面代碼託管平臺,能夠選擇付費服務sql

gitlab能夠認爲是一個開源的github,二者沒有直接關係


2、安裝svn

1.用yum安裝subversion

[root@subversion-server ~]# yum install -y subversion

2.建立版本庫

[root@subversion-server ~]# mkdir -p /data/svnroot/myproject
[root@subversion-server ~]# svnadmin create /data/svnroot/myproject
[root@subversion-server ~]# ls -l /data/svnroot/myproject/
conf/       format      locks/      
db/         hooks/      README.txt

3.編輯authz文件

[root@subversion-server conf]# vim svnserve.conf
// 在[groups]下增長以下內容
admin = svn_admin,nico
[/]
@admin = rw
* = r

[myproject:/]
nico = rw

4.編輯passwd文件

[root@subversion-server conf]# vim passwd 
# 添加以下內容
svn_admin = Aa123456
nico = Aa123456a
via = 123456Aa

5.編輯svnserve.conf

vim svnserve.conf 
[general]
anon-access = none
auth-access = write
password-db = passwd
authz-db = authz
realm = /data/svnroot/myproject

6.啓動svn

# -d 以daemon模式啓動svn
[root@subversion-server conf]# svnserve -d -r /data/svnroot 
[root@subversion-server conf]# netstat -nltp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1155/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1250/master         
tcp        0      0 0.0.0.0:3690            0.0.0.0:*               LISTEN      2008/svnserve       
tcp6       0      0 :::22                   :::*                    LISTEN      1155/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      1250/master


3、客戶端上使用svn(linux)

1.安裝subversion

[root@subversion-client ~]# yum -y install subversion

2.檢出代碼

[root@subversion-client ~]# svn checkout svn://192.168.1.37/myproject/ --username=svn_admin
Authentication realm: <svn://192.168.1.37:3690> /data/svnroot/myproject
Password for 'svn_admin': 

-----------------------------------------------------------------------
ATTENTION!  Your password for authentication realm:

   <svn://192.168.1.37:3690> /data/svnroot/myproject

can only be stored to disk unencrypted!  You are advised to configure
your system so that Subversion can store passwords encrypted, if
possible.  See the documentation for details.

You can avoid future appearances of this warning by setting the value
of the 'store-plaintext-passwords' option to either 'yes' or 'no' in
'/root/.subversion/servers'.
-----------------------------------------------------------------------
Store password unencrypted (yes/no)? yes
Checked out revision 0.

[root@subversion-client ~]# cd myproject/
[root@subversion-client myproject]# ls -al
total 0
drwxr-xr-x  3 root root  18 Aug 30 16:46 .
dr-xr-x---. 5 root root 222 Aug 30 16:46 ..
drwxr-xr-x  4 root root  75 Aug 30 16:46 .svn
  1. 添加文件到版本控制中心
[root@subversion-client myproject]# cp /etc/fstab .
[root@subversion-client myproject]# ll
total 4
-rw-r--r-- 1 root root 501 Aug 30 17:00 fstab
[root@subversion-client myproject]# svn add fstab 
A         fstab
[root@subversion-client myproject]# svn commit -m "add fstab"
Adding         fstab
Transmitting file data .
  1. 刪除文件
[root@subversion-client myproject]# 
[root@subversion-client myproject]# svn delete fstab
D         fstab
// 提交刪除
[root@subversion-client myproject]# svn commit -m "delete fstab"
Deleting       fstab

Committed revision 3.
// 更新本地文件到最到新
[root@subversion-client myproject]# svn update
Updating '.':
At revision 3.
[root@subversion-client myproject]#

5.查看變動日誌

[root@subversion-client myproject]# svn log
------------------------------------------------------------------------
r3 | svn_admin | 2018-08-30 17:41:19 +0800 (Thu, 30 Aug 2018) | 1 line

delete fstab
------------------------------------------------------------------------
r2 | svn_admin | 2018-08-30 17:29:54 +0800 (Thu, 30 Aug 2018) | 1 line

add README
------------------------------------------------------------------------
r1 | svn_admin | 2018-08-30 17:01:36 +0800 (Thu, 30 Aug 2018) | 1 line

add fstab
------------------------------------------------------------------------


4、客戶端上使用svn(windows)

1.下載TortoiseSVN,參考網址:https://tortoisesvn.net/downloads.zh.html

2.windows下安裝(略)

3.配置








4.在linux客戶端查看提交文件

[root@subversion-client myproject]# svn up
Updating '.':
A    svn_test.txt
Updated to revision 4.
[root@subversion-client myproject]# ls
README  svn_test.txt
[root@subversion-client myproject]#


5、單機上使用git

centos7默認已經安裝了git

[root@subversion-server ~]# rpm -q git
git-1.8.3.1-11.el7.x86_64
# 若是沒有安裝,可經過yum -y install git來安裝

1.創建代碼倉庫的目錄

[root@subversion-server ~]# mkdir -p /data/git
[root@subversion-server ~]# cd !$
cd /data/git

2.初始化倉庫

[root@subversion-server git]# git init
Initialized empty Git repository in /data/git/.git/
[root@subversion-server git]# ls -al
total 0
drwxr-xr-x 3 root root  18 Aug 30 22:40 .
drwxr-xr-x 4 root root  32 Aug 30 22:39 ..
drwxr-xr-x 7 root root 119 Aug 30 22:40 .git

[root@subversion-server git]# git config --global user.name "terry.he"
[root@subversion-server git]# git config --global user.email "kennminn@139.com"
[root@subversion-server git]# cat ~/.gitconfig 
[user]
        name = terry.he
        email = kennminn@139.com

3.建立一個提交

// 建立演示文件1.txt
[root@subversion-server git]#  echo -e  "123\naaa\n456\nbbb" > 1.txt 
[root@subversion-server git]# ls -l 1.txt
-rw-r--r-- 1 root root 24 Aug 30 22:45 1.txt

// 將1.txt添加到版本庫
[root@subversion-server git]# git add 1.txt
// 提交,只有提交之後才真正把文件提交到git倉庫
[root@subversion-server git]# git commit -m "add new file 1.txt"
[master (root-commit) b914c0a] add new file 1.txt
 1 file changed, 1 insertion(+)
 create mode 100644 1.txt

4.查看狀態

[root@subversion-server git]# echo "ccccc" >>1.txt
// 查看當前倉庫中的狀態,好比是否有改動的文件
[root@subversion-server git]# git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   1.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
// 相比較倉庫裏面的版本,1.txt本次修改了什麼內容,
[root@subversion-server git]# git diff 1.txt
diff --git a/1.txt b/1.txt
index 8e55d6a..a5e8574 100644
--- a/1.txt
+++ b/1.txt
@@ -1 +1,2 @@
  「123naaan456nbbb」
+ccccc

5.版本回退

// 屢次修改1.txt並提交 
[root@subversion-server git]# git add 1.txt
[root@subversion-server git]# git commit -m "1.txt m1"
[master 2df7319] 1.txt m1
 1 file changed, 1 insertion(+)
[root@subversion-server git]# echo "fffff" >> 1.txt
[root@subversion-server git]# git add 1.txt
[root@subversion-server git]# git commit -m "1.txt m2"
[master d357d00] 1.txt m2
 1 file changed, 1 insertion(+)
[root@subversion-server git]# cat 1.txt
 「123naaan456nbbb」
ccccc
fffff
// 查看提交記錄
[root@subversion-server git]# git log
commit d357d00c2cf9cd868c510d21d143786eb438b8ed
Author: terry.he <kennminn@139.com>
Date:   Thu Aug 30 23:08:23 2018 +0800

    1.txt m2

commit 2df731931d2019027d51d1ac5847534b9c721480
Author: terry.he <kennminn@139.com>
Date:   Thu Aug 30 23:07:33 2018 +0800

    1.txt m1

commit b914c0ab86a6f69de8ed0ca4ae148e5be78ddc7d
Author: terry.he <kennminn@139.com>
Date:   Thu Aug 30 22:47:43 2018 +0800

    add new file 1.txt

// 將提交記錄以單行顯示
[root@subversion-server git]# git log --pretty=oneline
d357d00c2cf9cd868c510d21d143786eb438b8ed 1.txt m2
2df731931d2019027d51d1ac5847534b9c721480 1.txt m1
b914c0ab86a6f69de8ed0ca4ae148e5be78ddc7d add new file 1.txt

//回退到m1修改時的狀態,m2修改沒有了
[root@subversion-server git]# git reset --hard 2df731931d
HEAD is now at 2df7319 1.txt m1
[root@subversion-server git]# cat 1.txt 
 「123naaan456nbbb」
ccccc

//回退到第1次添加的時候,回到第一次修改的狀態
[root@subversion-server git]# git reset --hard b914c0ab86a
HEAD is now at b914c0a add new file 1.txt
[root@subversion-server git]# cat 1.txt 
 「123naaan456nbbb」

//查看全部歷史版本
[root@subversion-server git]# git reflog
b914c0a HEAD@{0}: reset: moving to b914c0ab86a
2df7319 HEAD@{1}: reset: moving to 2df731931d
d357d00 HEAD@{2}: commit: 1.txt m2
2df7319 HEAD@{3}: commit: 1.txt m1
b914c0a HEAD@{4}: commit (initial): add new file 1.txt

//回退到m2修改狀態
[root@subversion-server git]# git reset --hard d357d00
HEAD is now at d357d00 1.txt m2
[root@subversion-server git]# cat 1.txt 
 「123naaan456nbbb」
ccccc
fffff

6.撤銷修改

// 刪除1.txt
[root@subversion-server git]# rm -f 1.txt
[root@subversion-server git]# git checkout -- 1.txt
[root@subversion-server git]# ll
total 4
-rw-r--r-- 1 root root 36 Aug 30 23:19 1.txt

// 若是1.txt文件修改,add後但沒有commit,再想回退到上一次提交的狀態,
// 可使用git reset HEAD 1.txt,再執行git checkout -- 1.txt
[root@subversion-server git]# echo "eeeeee" >>1.txt
[root@subversion-server git]# cat 1,txt
cat: 1,txt: No such file or directory
[root@subversion-server git]# cat 1.txt
 「123naaan456nbbb」
ccccc
fffff
eeeeee
[root@subversion-server git]# git add 1.txt
[root@subversion-server git]# cat 1.txt
 「123naaan456nbbb」
ccccc
fffff
eeeeee
[root@subversion-server git]# git reset HEAD 1.txt
Unstaged changes after reset:
M       1.txt
[root@subversion-server git]# git checkout -- 1.txt
[root@subversion-server git]# cat 1.txt
 「123naaan456nbbb」
ccccc
fffff

7.刪除文件

[root@subversion-server git]# git add 2.txt
[root@subversion-server git]# git commit -m "add new file 2.txt"
[master 9e6bc56] add new file 2.txt
 1 file changed, 2 insertions(+)
 create mode 100644 2.txt
[root@subversion-server git]# git log
commit 9e6bc56eea5adbdb76b5d6dfef64d9c7f5599ea5
Author: terry.he <kennminn@139.com>
Date:   Thu Aug 30 23:26:07 2018 +0800

    add new file 2.txt

commit d357d00c2cf9cd868c510d21d143786eb438b8ed
Author: terry.he <kennminn@139.com>
Date:   Thu Aug 30 23:08:23 2018 +0800

    1.txt m2

commit 2df731931d2019027d51d1ac5847534b9c721480
Author: terry.he <kennminn@139.com>
Date:   Thu Aug 30 23:07:33 2018 +0800

    1.txt m1

commit b914c0ab86a6f69de8ed0ca4ae148e5be78ddc7d
Author: terry.he <kennminn@139.com>
Date:   Thu Aug 30 22:47:43 2018 +0800

    add new file 1.txt
[root@subversion-server git]# 
[root@subversion-server git]# 
[root@subversion-server git]# git rm 2.txt
rm '2.txt'
[root@subversion-server git]# git commit -m "delete 2.txt"
[master e127514] delete 2.txt
 1 file changed, 2 deletions(-)
 delete mode 100644 2.txt
 
[root@subversion-server git]# ll
total 4
-rw-r--r-- 1 root root 36 Aug 30 23:22 1.txt
-rw-r--r-- 1 root root 36 Aug 30 23:22 1.txt
[root@subversion-server git]# git log
commit e12751488b71737013eea59ddf712547b71e6b79
Author: terry.he <kennminn@139.com>
Date:   Thu Aug 30 23:26:39 2018 +0800

    delete 2.txt

commit 9e6bc56eea5adbdb76b5d6dfef64d9c7f5599ea5
Author: terry.he <kennminn@139.com>
Date:   Thu Aug 30 23:26:07 2018 +0800

    add new file 2.txt

commit d357d00c2cf9cd868c510d21d143786eb438b8ed
Author: terry.he <kennminn@139.com>
Date:   Thu Aug 30 23:08:23 2018 +0800

    1.txt m2

commit 2df731931d2019027d51d1ac5847534b9c721480
...下略...


6、創建遠程倉庫

1.在github網站註冊一個賬戶(略),網址:https://github.com/

2.在linux中建立密鑰對並添加公鑰到github

// Linux中建立密鑰對
[root@lanquark ~]# ssh-keygen 
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:FAAVQAEPj1cMQcaKx17lHlvB6KNunaHGHgxbpNrY3Cw root@lanquark.com
The key's randomart image is:
+---[RSA 2048]----+
|  o=XO==.        |
|   *..+ o.       |
| o..=+  ..       |
|. ++. =..        |
| oo..o =S        |
| *.B. +          |
|o Eo=o o         |
|   .*.o          |
|   +.            |
+----[SHA256]-----+
[root@lanquark ~]# cat ~/.ssh/id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDgoSerO+uSEOxoVkLsEUQqzmPNZkM39Eib31QO9NDp5/TFT35Zp0C4Rsbgka3hWnHM/6XHA+dOczyPockYQ30VG+W0jwXOTQe5Vrx8AKDFLAjKtOlNQXYVCJ7TTXGCdNAQIpE9pnCWUfIjjnkBcbvrSWWfgdFqC7VSPul5wVDN3BY+sHHRVei9vT1vPyQhtrHKA9fbrVWrEwL8LJ9GP5vz1EB+LlOyAu0EZtiX+KtZeO3PXWNtZO/PQZ3jo2+EWgoW2SsBPMGK0vEBMrc8xZkeOqABOQhlwOgdr/LL1DNXoXwWLh49BP/nKkb5Yxl2I6zDq9X2D+rn9Qulkr+9AhBJ root@lanquark.com

github中添加公鑰




驗證添加公鑰成功

[root@lanquark ~]# ssh -T git@github.com
The authenticity of host 'github.com (13.250.177.223)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
RSA key fingerprint is MD5:16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,13.250.177.223' (RSA) to the list of known hosts.
Hi szkennminn! You've successfully authenticated, but GitHub does not provide shell access.

github中新建倉庫



本地倉庫與遠程倉庫關聯

[root@lanquark ~]# mkdir hello-kennminn
[root@lanquark ~]# cd hello-kennminn/
[root@lanquark hello-kennminn]# git init 
Initialized empty Git repository in /root/hello-kennminn/.git/
[root@lanquark hello-kennminn]# git remote add origin git@github.com:szkennminn/hello-kennminn.git
[root@lanquark hello-kennminn]# git push -u origin master
[root@lanquark hello-kennminn]# echo "333333" >>3.txt
[root@lanquark hello-kennminn]# git add 3.txt
[root@lanquark hello-kennminn]# git commit -m "add new file 3.txt"
[master f71652b] add new file 3.txt
 Committer: root <root@lanquark.com>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 1 insertion(+)
 create mode 100644 3.txt
[root@lanquark hello-kennminn]# git push
Counting objects: 4, done.
Delta compression using up to 4 threads.
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)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To git@github.com:szkennminn/hello-kennminn.git
   74fa933..f71652b  master -> master


7、克隆遠程倉庫

1.複製倉庫路徑

2.克隆遠程倉庫

[root@lanquark ~]# git clone git@github.com:szkennminn/hello-kennminn.git
Cloning into 'hello-kennminn'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
[root@lanquark ~]# cd hello-kennminn/
[root@lanquark hello-kennminn]#

3.測試遠程推送文件

[root@lanquark hello-kennminn]# echo 'hello world!' >> hello.txt
[root@lanquark hello-kennminn]# git add hello.txt
[root@lanquark hello-kennminn]# git commit -m "add new file hello.txt"
[master ebba4a1] add new file hello.txt
 Committer: root <root@lanquark.com>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 1 insertion(+)
 create mode 100644 hello.txt
[root@lanquark hello-kennminn]# git log
commit ebba4a1cb1df783bfa325257d449ab7b9317e272
Author: root <root@lanquark.com>
Date:   Fri Aug 31 00:42:08 2018 +0800

    add new file hello.txt

commit 9780698cd38c4aa27a395004191e6a94d4f83308
Author: szkennminn <h.toniguy@gmail.com>
Date:   Fri Aug 31 00:35:55 2018 +0800

    Initial commit
[root@lanquark hello-kennminn]# git push
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 289 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:szkennminn/hello-kennminn.git
   9780698..ebba4a1  master -> master
[root@lanquark hello-kennminn]#

github檢查


8、分支管理

1.建立並切換分支(branch)

// 查看分支, 當前分支前面會標一個*號。
[root@lanquark hello-kennminn]# git branch
* master

// 建立並切換分支
[root@lanquark hello-kennminn]# git checkout -b "nico"
Switched to a new branch 'nico'
[root@lanquark hello-kennminn]# git branch
  master
* nico

// 分支下修改並提交
[root@lanquark hello-kennminn]# echo "afnalfnasnfasf" >>hello.txt 
[root@lanquark hello-kennminn]# cat hello.txt 
hello world!
afnalfnasnfasf
* nico
[root@lanquark hello-kennminn]# echo "afnalfnasnfasf" >>hello.txt 
[root@lanquark hello-kennminn]# cat hello.txt 
hello world!
afnalfnasnfasf
[root@lanquark hello-kennminn]# git add hello.txt
[root@lanquark hello-kennminn]# git commit -m "branch test modified 1 hello.txt" 
[nico a8ed366] branch test modified 1 hello.txt
 Committer: root <root@lanquark.com>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 1 insertion(+)
 
// 切換回master分支
[root@lanquark hello-kennminn]# git checkout master
Switched to branch 'master'
[root@lanquark hello-kennminn]# git branch
* master
  nico
// 分支作的修改消失了
[root@lanquark hello-kennminn]# cat hello.txt 
hello world!

2.合併分支

// 把分支nico合併到master分支
// git merge命令用於合併指定分支到當前分支。
[root@lanquark hello-kennminn]# git merge nico
Updating f71652b..a8ed366
Fast-forward
 hello.txt | 1 +
 1 file changed, 1 insertion(+)
[root@lanquark hello-kennminn]# cat hello.txt 
hello world!
afnalfnasnfasf

3.解決衝突

// 在nico分支修改hello.txt
[root@lanquark hello-kennminn]# git checkout nico 
Switched to branch 'nico'
[root@lanquark hello-kennminn]# git branch
  master
* nico
[root@lanquark hello-kennminn]# echo "new line is add to hello" >>hello.txt 
[root@lanquark hello-kennminn]# git add hello.txt
[root@lanquark hello-kennminn]# git commit -m "add new line to hello.txt"
[nico 450957a] add new line to hello.txt
// 切回主分支
[root@lanquark hello-kennminn]# git checkout master 
Switched to branch 'master'
// 修改hello.txt內容
[root@lanquark hello-kennminn]# cat hello.txt 
hello world!
afnalfnasnfasf
[root@lanquark hello-kennminn]# echo "hahahaha" >> hello.txt      
[root@lanquark hello-kennminn]# cat hello.txt 
hello world!
afnalfnasnfasf
hahahaha
[root@lanquark hello-kennminn]# git add hello.txt
[root@lanquark hello-kennminn]# git commit -m "conflict test add some content to hello.txt from master"
[master 71b6c4b] conflict test add some content to hello.txt from master
 1 file changed, 1 insertion(+)
 
// 合併nico分支,由於master和nico分支下都對hello.txt作了修改,合併時可能會產生衝突
[root@lanquark hello-kennminn]# git merge nico
Auto-merging hello.txt
CONFLICT (content): Merge conflict in hello.txt
Automatic merge failed; fix conflicts and then commit the result.
// 查看hello.txt的內容
[root@lanquark hello-kennminn]# vim hello.txt 
hello world!
afnalfnasnfasf
<<<<<<< HEAD
hahahahah
=======
new line1 is add to hello
>>>>>>> nico
// 須要手動修改後再提交合並
// 若是master分支和nico分支都對hello.txt進行了編輯,當合並時會提示衝突,須要先解
// 決衝突才能夠繼續合併。
// 解決衝突的方法是在master分支下,編輯hello.txt,改成nico分支裏面hello.txt的內
// 容。 而後提交hello.txt,再合併nico分支。
// 可是這樣有一個問題,萬一master分支更改的內容是咱們想要的呢? 能夠編輯hello.txt
// 內容,改成想要的,而後提交。切換到nico分支,而後合併master分支到nico分支便可
//(倒着合併)。合併分支有一個原則,那就是要把最新的分支合併到舊的分支。也就是說
// merge後面跟的分支名字必定是最新的分支。
[root@lanquark hello-kennminn]# vim hello.txt 
hello world!
afnalfnasnfasf
new line1 is add to hello
[root@lanquark hello-kennminn]# git add hello.txt
[root@lanquark hello-kennminn]# git commit -m "conflict fixed"  
[master 01bcded] conflict fixed
[root@lanquark hello-kennminn]# git merge nico
Already up-to-date.
// 查看分支的合併狀況
[root@lanquark hello-kennminn]#  git log --graph --pretty=oneline --abbrev-commit
*   01bcded conflict fixed
|\  
| * 3a7b366 add newline 1 to hello.txt
| * 450957a add new line to hello.txt
| * a8ed366 branch test modified 1 hello.txt
* | 71b6c4b conflict test add some content to hello.txt from master
* | 12c2130 branch test modified 1 hello.txt
|/  
* f71652b add new file 3.txt
*   74fa933 Merge branch 'master' of github.com:szkennminn/hello-kennminn
|\  
| * ebba4a1 add new file hello.txt
| * 9780698 Initial commit
* c930706 add new file 2.txt

4.刪除分支

// 刪除nico分支 
[root@lanquark hello-kennminn]# git branch -d nico
Deleted branch nico (was 3a7b366).
// 若是分支沒有合併,刪除以前會提示,那就不合並,強制刪除
// git branch -D aming


9、遠程分支管理

  1. 使用分支的原則

對於分支的應用,建議你們以這樣的原則來:

master分支是很是重要的,線上發佈代碼用這個分支,平時咱們開發代碼不要在這個分支上。

建立一個dev分支,專門用做開發,只有當發佈到線上以前,纔會把dev分支合併到master

開發人員應該在dev的基礎上再分支成我的分支,我的分支(在本身pc上)裏面開發代碼,而後合併到dev分支

2.遠程分支

本地新建的分支若是不推送到遠程,對其餘人就是不可見的

查看遠程分支

[root@lanquark hello-kennminn]# git ls-remote origin      
f71652b9a8dc959b6558d3600660cbf59f8baa65        HEAD
f71652b9a8dc959b6558d3600660cbf59f8baa65        refs/heads/master

github上建立新分支dev

[root@lanquark hello-kennminn]# git ls-remote origin
f71652b9a8dc959b6558d3600660cbf59f8baa65        HEAD
f71652b9a8dc959b6558d3600660cbf59f8baa65        refs/heads/dev
f71652b9a8dc959b6558d3600660cbf59f8baa65        refs/heads/master

// 在分支建立文件並push
// 對於git push分支分兩種狀況
// 當本地分支和遠程分支一致時
// git push會把全部本地分支的變動一同推送到遠程,若是想只推送一個分支,使用git push // origin branch-name
// 當本地分支比遠程分支多,默認git push 只推送本地和遠程一致的分支,想要把多出來的
// 本地分支推送到遠程時,使用git push origin branch-name  若是推送失敗,先用git // pull抓取遠程的新提交

[root@lanquark hello-kennminn]# echo -e "aaaaa\nbbbbb\nccccc\nddddddd" >file_dev.txt 
[root@lanquark hello-kennminn]# cat file_dev.txt 
aaaaa
bbbbb
ccccc
ddddddd
[root@lanquark hello-kennminn]# gti add file_dev.txt 
-bash: gti: command not found
[root@lanquark hello-kennminn]# git add file_dev.txt  
[root@lanquark hello-kennminn]# git commit -m "remote branch test"
[dev e1666d5] remote branch test
 1 file changed, 4 insertions(+)
 create mode 100644 file_dev.txt
// 本地分支與遠程分支致
[root@lanquark hello-kennminn]# git push 
Counting objects: 19, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (14/14), done.
Writing objects: 100% (17/17), 1.73 KiB | 0 bytes/s, done.
Total 17 (delta 4), reused 0 (delta 0)
remote: Resolving deltas: 100% (4/4), completed with 1 local object.
To git@github.com:szkennminn/hello-kennminn.git
   f71652b..e1666d5  dev -> dev
   f71652b..01bcded  master -> master
// 本地分支與遠程分支不一致
[root@lanquark hello-kennminn]# git branch dev2
[root@lanquark hello-kennminn]# git checkout dev2
Switched to branch 'dev2'
[root@lanquark hello-kennminn]# echo "branchtest" >aaaa.txt
[root@lanquark hello-kennminn]# git add aaaa.txt    
[root@lanquark hello-kennminn]# git commit -m "add aaaa.txt to dev2"
[dev2 9e508b3] add aaaa.txt to dev2
 1 file changed, 1 insertion(+)
 create mode 100644 aaaa.txt
[root@lanquark hello-kennminn]# git push
Everything up-to-date
[root@lanquark hello-kennminn]# git ls-remote origin
01bcdedfbbe08eb357fece1196ceece1a2d97c9c        HEAD
e1666d5b341fb168eee1e87d1609aa1e77c3e0c7        refs/heads/dev
01bcdedfbbe08eb357fece1196ceece1a2d97c9c        refs/heads/master
[root@lanquark hello-kennminn]# git push origin dev2
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 276 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To git@github.com:szkennminn/hello-kennminn.git
 * [new branch]      dev2 -> dev2
[root@lanquark hello-kennminn]# git ls-remote origin
01bcdedfbbe08eb357fece1196ceece1a2d97c9c        HEAD
e1666d5b341fb168eee1e87d1609aa1e77c3e0c7        refs/heads/dev
9e508b3cff47a624649d67873ac0732f1fd4c8c3        refs/heads/dev2
01bcdedfbbe08eb357fece1196ceece1a2d97c9c        refs/heads/master


10、標籤管理

標籤相似於快照功能,能夠給版本庫打一個標籤,記錄某個時刻庫的狀態。也能夠隨時恢復到該狀態。

1.打標籤

// 首先切回主分支
[root@lanquark hello-kennminn]# git branch 
  dev
* dev2
  master
[root@lanquark hello-kennminn]# git checkout master
Switched to branch 'master'
// 打標籤,打標籤針對commit,因此能夠針對歷史的commit來打tag
[root@lanquark hello-kennminn]# git tag v1.0
// 顯示標籤
[root@lanquark hello-kennminn]# git show v1.0
commit 01bcdedfbbe08eb357fece1196ceece1a2d97c9c
Merge: 71b6c4b 3a7b366
Author: Terry He <kennminn@139.com>
Date:   Fri Aug 31 10:46:14 2018 +0800

    conflict fixed

2.顯示全部的標籤

// 當前只有一個標籤
[root@lanquark hello-kennminn]# git tag
v1.0

3.針對歷史commit打標籤

// git log --pretty=oneline --abbrev-commit 也能夠
[root@lanquark hello-kennminn]# git log --pretty=oneline 
01bcdedfbbe08eb357fece1196ceece1a2d97c9c conflict fixed
71b6c4b88498550b0d76211c3555b11547c1b8c0 conflict test add some content to hello.txt from master
3a7b366542bcea232e2efe08acda7b2ffd32597f add newline 1 to hello.txt
12c2130d2903d4db9cdfba8ef920dcd6d8bdb900 branch test modified 1 hello.txt
450957aab8ce94df36b87be19cba171abfefd076 add new line to hello.txt
a8ed3666b79126fcf535c9977a2ca69c29805431 branch test modified 1 hello.txt
f71652b9a8dc959b6558d3600660cbf59f8baa65 add new file 3.txt
74fa9332aaac1d98dd332ae8f8727ecd8721a167 Merge branch 'master' of github.com:szkennminn/hello-kennminn
c930706b51acb0f0731fa3cea73421c52eec742d add new file 2.txt
ebba4a1cb1df783bfa325257d449ab7b9317e272 add new file hello.txt
9780698cd38c4aa27a395004191e6a94d4f83308 Initial commit
// 給歷史提交打標籤
[root@lanquark hello-kennminn]# git tag v0.9 3a7b366542b
// 給歷史提交打標籤並添加描述
[root@lanquark hello-kennminn]# git tag v0.8 -m "test for add description with tag" 450957aab8               
[root@lanquark hello-kennminn]# git tag
v0.8
v0.9
v1.0

4.刪除標籤

[root@lanquark hello-kennminn]# git tag -d v0.8 
Deleted tag 'v0.8' (was 92086fc)
[root@lanquark hello-kennminn]# git tag
v0.9
v1.0

5.推送指定標籤到遠程

[root@lanquark hello-kennminn]# git push origin v1.0
Total 0 (delta 0), reused 0 (delta 0)
To git@github.com:szkennminn/hello-kennminn.git
 * [new tag]         v1.0 -> v1.0

[root@lanquark hello-kennminn]# git ls-remote origin
01bcdedfbbe08eb357fece1196ceece1a2d97c9c        HEAD
e1666d5b341fb168eee1e87d1609aa1e77c3e0c7        refs/heads/dev
9e508b3cff47a624649d67873ac0732f1fd4c8c3        refs/heads/dev2
01bcdedfbbe08eb357fece1196ceece1a2d97c9c        refs/heads/master
01bcdedfbbe08eb357fece1196ceece1a2d97c9c        refs/tags/v1.0


6.推送全部標籤

[root@lanquark hello-kennminn]# git push --tag origin    
Total 0 (delta 0), reused 0 (delta 0)
To git@github.com:szkennminn/hello-kennminn.git
 * [new tag]         v0.9 -> v0.9
[root@lanquark hello-kennminn]# git ls-remote origin  
01bcdedfbbe08eb357fece1196ceece1a2d97c9c        HEAD
e1666d5b341fb168eee1e87d1609aa1e77c3e0c7        refs/heads/dev
9e508b3cff47a624649d67873ac0732f1fd4c8c3        refs/heads/dev2
01bcdedfbbe08eb357fece1196ceece1a2d97c9c        refs/heads/master
3a7b366542bcea232e2efe08acda7b2ffd32597f        refs/tags/v0.9
01bcdedfbbe08eb357fece1196ceece1a2d97c9c        refs/tags/v1.0


7.本地刪除標籤,並推送到遠程

[root@lanquark hello-kennminn]# git tag -d v1.0
Deleted tag 'v1.0' (was 01bcded)
[root@lanquark hello-kennminn]# git push origin :refs/tags/v1.0 
To git@github.com:szkennminn/hello-kennminn.git
 - [deleted]         v1.0



11、git別名

git別名相似於linux shell中的別名,用別名能夠提升咱們的工做效率。

1.添加別名

// 定義commit別名ci
[root@lanquark hello-kennminn]# git config --global alias.ci commit
[root@lanquark hello-kennminn]# echo "412313131" >> ff.txt
[root@lanquark hello-kennminn]# git add ff.txt
[root@lanquark hello-kennminn]# git ci -m "add new file ff.txt"
[master f7ea5c1] add new file ff.txt
 1 file changed, 1 insertion(+)
 create mode 100644 ff.txt
[root@lanquark hello-kennminn]# git config --global alias.br branch
[root@lanquark hello-kennminn]# git br
  dev
  dev2
* master

2.查看別名

[root@lanquark hello-kennminn]# git config --list| grep alias
alias.ci=commit
alias.br=branch
// 若是不加grep alias也能夠看到,可是輸出內容比較多
// git的配置文件位置 ~/.gitconfig
[root@lanquark hello-kennminn]# git config --list
push.default=matching
user.name=Terry He
user.email=kennminn@139.com
alias.ci=commit
alias.br=branch
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=git@github.com:szkennminn/hello-kennminn.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*

3.取消別名

[root@lanquark hello-kennminn]# git config --global --unset alias.br 
[root@lanquark hello-kennminn]# git config --list| grep alias  
alias.ci=commit

4.查詢log小技巧(格式化)

[root@lanquark hello-kennminn]# 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@lanquark hello-kennminn]# git lg
* f7ea5c1 - (HEAD, master) add new file ff.txt (10 minutes ago) <Terry He>
*   01bcded - (origin/master) conflict fixed (3 days ago) <Terry He>
|\  
| * 3a7b366 - (tag: v0.9) add newline 1 to hello.txt (3 days ago) <Terry He>
| * 450957a - add new line to hello.txt (3 days ago) <root>
| * a8ed366 - branch test modified 1 hello.txt (3 days ago) <root>
* | 71b6c4b - conflict test add some content to hello.txt from master (3 days ago) <Terry He>
* | 12c2130 - branch test modified 1 hello.txt (3 days ago) <Terry He>
|/  
* f71652b - add new file 3.txt (3 days ago) <root>
*   74fa933 - Merge branch 'master' of github.com:szkennminn/hello-kennminn (3 days ago) <root>
|\  
| * ebba4a1 - add new file hello.txt (3 days ago) <root>
| * 9780698 - Initial commit (3 days ago) <szkennminn>
* c930706 - add new file 2.txt (3 days ago) <root>


12、搭建git服務器

github是公開的服務平臺,免費倉庫對全部人可見,可倉庫數會有限制,其私有倉庫又得花錢買。因此咱們能夠想辦法搭建一個私有的,只供本身公司內部使用的。Gitlab是個不錯的選擇。在介紹它以前,先講述一下命令行的git服務器

1.安裝git

// 默認git已經安裝
[root@eurodesign ~]# rpm -q git
git-1.8.3.1-11.el7.x86_64
// 若沒有安裝,能夠經過yum方式安裝,yum -y install git

2.建立git用戶

[root@eurodesign ~]# useradd -s /usr/bin/git-shell git
[root@eurodesign ~]# id git
uid=1000(git) gid=1000(git) groups=1000(git)
[root@eurodesign ~]# cd /home/git/

3.建立authorized_keys文件,並修改權限和屬主

[root@eurodesign git]# mkdir -p .ssh
[root@eurodesign git]# touch .ssh/authorized_keys
[root@eurodesign git]# chmod 600 !$
chmod 600 .ssh/authorized_keys
[root@eurodesign git]# chown -R git:git .ssh
// 上傳客戶端公鑰(略)並在客戶端測試
[root@subversion-server ~]# ssh git@192.168.1.38
fatal: Interactive git shell is not enabled.
hint: ~/git-shell-commands should exist and have read and execute access.
Connection to 192.168.1.38 closed.

3.在服務器端設定git倉庫目錄

[root@eurodesign git]# mkdir -p /data/gitroot
[root@eurodesign git]# cd !$
cd /data/gitroot
// 建立裸建立
[root@eurodesign gitroot]#  git init --bare sample.git 
Initialized empty Git repository in /data/gitroot/sample.git/
[root@eurodesign gitroot]# chown -R git.git sample.git

4.客戶端克隆服務器上的倉庫

// 克隆服務器上的倉庫
[root@subversion-server ~]# git clone git@192.168.1.38:/data/gitroot/sample.git
Cloning into 'sample'...
warning: You appear to have cloned an empty repository.
[root@subversion-server ~]# cd sample/
[root@subversion-server sample]# ls -al
total 0
drwxr-xr-x  3 root root  18 Sep  3 11:49 .
dr-xr-x---. 5 root root 237 Sep  3 11:49 ..
drwxr-xr-x  7 root root 119 Sep  3 11:49 .git
// 測試提交
[root@subversion-server sample]# echo "asdadasda" >> my.txt
[root@subversion-server sample]# git add my.txt
[root@subversion-server sample]# git commit -m "add new file my.txt"
[master (root-commit) dbb9661] add new file my.txt
 1 file changed, 1 insertion(+)
 create mode 100644 my.txt
[root@subversion-server sample]# git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 218 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@192.168.1.38:/data/gitroot/sample.git
 * [new branch]      master -> master
[root@subversion-server sample]# git ls-remote origin 
dbb96612232686fc529bd286af2ce84ab45cdf7a        HEAD
dbb96612232686fc529bd286af2ce84ab45cdf7a        refs/heads/master
// 測試拉取數據,
// 進入/tmp目錄,再次克隆sample倉庫
[root@subversion-server sample]# cd /tmp/
[root@subversion-server tmp]# git clone git@192.168.1.38:/data/gitroot/sample.git
Cloning into 'sample'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
[root@subversion-server tmp]# cd sample/
[root@subversion-server sample]# ll
total 4
-rw-r--r-- 1 root root 10 Sep  3 11:53 my.txt
[root@subversion-server sample]# echo "modified something" >>my.txt
[root@subversion-server sample]# git add my.txt
[root@subversion-server sample]# git commit -m "modified my.txt"
[master 1222a99] modified my.txt
 1 file changed, 1 insertion(+)
[root@subversion-server sample]# git push 
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Counting objects: 5, done.
Writing objects: 100% (3/3), 264 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@192.168.1.38:/data/gitroot/sample.git
   dbb9661..1222a99  master -> master
   
// 切換回/root/sample
[root@subversion-server sample]# cd /root/sample/
[root@subversion-server sample]# cat my.txt 
asdadasda
[root@subversion-server sample]# git pull
remote: Counting objects: 5, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From 192.168.1.38:/data/gitroot/sample
   dbb9661..1222a99  master     -> origin/master
Updating dbb9661..1222a99
Fast-forward
 my.txt | 1 +
 1 file changed, 1 insertion(+)
[root@subversion-server sample]# cat my.txt 
asdadasda
modified something


十3、安裝gitlab

gitlab是相似於guthub的一種開源實現。

gitlab官網 https://about.gitlab.com/gitlab-com/

官方安裝文檔 https://about.gitlab.com/installation/?version=ce#centos-7 (ce/ee)

要求服務器內存很多於2gb

1.安裝與配置必須的依賴

// openssh-server和openssh-client默認最小化安裝已經帶,因此能夠不用安裝
[root@gitlab ~]#  yum install -y curl policycoreutils-python openssh-server openssh-clients 
// 調整防火牆策略,爲方便實驗,已經關閉防火牆
[root@gitlab ~]# firewall-cmd --permanent --add-service=http
[root@gitlab ~]# systemctl reload firewalld
// 如需郵件通知,能夠自行配置第三方的郵件服務器或安裝posix
// yum install postfix
// systemctl enable postfix
// systemctl start postfix

2.添加gitlab安裝源

[root@gitlab ~]# curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
[root@gitlab ~]# yum repolist 
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirror.premi.st
 * extras: mirrors.aliyun.com
 * updates: mirrors.shu.edu.cn
repo id                                                               repo name                                                                                    status
base/7/x86_64                                                         CentOS-7 - Base                                                                               9,911
epel/x86_64                                                           Extra Packages for Enterprise Linux 7 - x86_64                                               12,663
extras/7/x86_64                                                       CentOS-7 - Extras                                                                               402
gitlab_gitlab-ce/x86_64                                               gitlab_gitlab-ce                                                                                390
gitlab_gitlab-ce-source                                               gitlab_gitlab-ce-source                                                                           0
updates/7/x86_64                                                      CentOS-7 - Updates                                                                            1,333
repolist: 24,699

3.安裝gitlab社區版

[root@gitlab ~]# yum install -y gitlab-ce

4.配置gitlab

[root@gitlab ~]# gitlab-ctl reconfigure

5.查看gitlab啓動端口

[root@gitlab ~]# netstat -nltp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:8060            0.0.0.0:*               LISTEN      2611/nginx: master  
tcp        0      0 127.0.0.1:9121          0.0.0.0:*               LISTEN      2897/redis_exporter 
tcp        0      0 127.0.0.1:9090          0.0.0.0:*               LISTEN      3128/prometheus     
tcp        0      0 127.0.0.1:9187          0.0.0.0:*               LISTEN      3241/postgres_expor 
tcp        0      0 127.0.0.1:9093          0.0.0.0:*               LISTEN      3147/alertmanager   
tcp        0      0 127.0.0.1:9100          0.0.0.0:*               LISTEN      2860/node_exporter  
tcp        0      0 127.0.0.1:9229          0.0.0.0:*               LISTEN      3058/gitlab-workhor 
tcp        0      0 127.0.0.1:9168          0.0.0.0:*               LISTEN      3110/ruby           
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      2552/unicorn master 
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      2611/nginx: master  
tcp        0      0 127.0.0.1:8082          0.0.0.0:*               LISTEN      2572/sidekiq 5.1.3  
tcp        0      0 127.0.0.1:9236          0.0.0.0:*               LISTEN      3078/gitaly         
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      779/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      880/master          
tcp6       0      0 :::9094                 :::*                    LISTEN      3147/alertmanager   
tcp6       0      0 ::1:9168                :::*                    LISTEN      3110/ruby           
tcp6       0      0 :::22                   :::*                    LISTEN      779/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      880/master

6.gitlab進程管理

// 查看gitlab狀態
[root@gitlab ~]# gitlab-ctl status
run: alertmanager: (pid 3147) 1458s; run: log: (pid 3256) 1457s
run: gitaly: (pid 3078) 1459s; run: log: (pid 3232) 1458s
run: gitlab-monitor: (pid 3110) 1459s; run: log: (pid 3248) 1457s
run: gitlab-workhorse: (pid 3058) 1460s; run: log: (pid 3125) 1458s
run: logrotate: (pid 2651) 1503s; run: log: (pid 3127) 1458s
run: nginx: (pid 2611) 1509s; run: log: (pid 3126) 1458s
run: node-exporter: (pid 2860) 1491s; run: log: (pid 3103) 1459s
run: postgres-exporter: (pid 3241) 1458s; run: log: (pid 3260) 1456s
run: postgresql: (pid 2332) 1545s; run: log: (pid 3112) 1459s
run: prometheus: (pid 3128) 1458s; run: log: (pid 3252) 1457s
run: redis: (pid 2272) 1551s; run: log: (pid 3048) 1460s
run: redis-exporter: (pid 2897) 1483s; run: log: (pid 3118) 1458s
run: sidekiq: (pid 2572) 1513s; run: log: (pid 3051) 1460s
run: unicorn: (pid 2534) 1519s; run: log: (pid 3113) 1459s
// 中止gitlab
[root@gitlab ~]# gitlab-ctl stop
ok: down: alertmanager: 1s, normally up
ok: down: gitaly: 0s, normally up
ok: down: gitlab-monitor: 1s, normally up
ok: down: gitlab-workhorse: 0s, normally up
ok: down: logrotate: 0s, normally up
ok: down: nginx: 1s, normally up
ok: down: node-exporter: 0s, normally up
ok: down: postgres-exporter: 1s, normally up
ok: down: postgresql: 0s, normally up
ok: down: prometheus: 1s, normally up
ok: down: redis: 0s, normally up
ok: down: redis-exporter: 0s, normally up
ok: down: sidekiq: 0s, normally up
ok: down: unicorn: 1s, normally up
// 啓動gitlab
[root@gitlab ~]# gitlab-ctl start
ok: run: alertmanager: (pid 6374) 0s
ok: run: gitaly: (pid 6388) 1s
ok: run: gitlab-monitor: (pid 6400) 0s
ok: run: gitlab-workhorse: (pid 6404) 0s
ok: run: logrotate: (pid 6413) 1s
ok: run: nginx: (pid 6435) 0s
ok: run: node-exporter: (pid 6443) 1s
ok: run: postgres-exporter: (pid 6450) 0s
ok: run: postgresql: (pid 6457) 0s
ok: run: prometheus: (pid 6465) 1s
ok: run: redis: (pid 6480) 0s
ok: run: redis-exporter: (pid 6484) 1s
ok: run: sidekiq: (pid 6565) 0s
ok: run: unicorn: (pid 6572) 1s

7.初始訪問(經過web)



十4、使用gitlab

gitlab經常使用命令

https://www.cnyunwei.cc/archives/1204

1.建立用戶

2.建立組

3.建立項目

4.添加用戶公鑰


十5、gitlab備份和恢復

1.gitlab備份

// 備份,在線備份
[root@gitlab ~]# gitlab-rake gitlab:backup:create
Dumping database ... 
Dumping PostgreSQL database gitlabhq_production ... [DONE]
done
Dumping repositories ...
 * nico/nginx_module ... [DONE]
[SKIPPED] Wiki
done
Dumping uploads ... 
done
Dumping builds ... 
done
Dumping artifacts ... 
done
Dumping pages ... 
done
Dumping lfs objects ... 
done
Dumping container registry images ... 
[DISABLED]
Creating backup archive: 1535959505_2018_09_03_11.2.3_gitlab_backup.tar ... done
Uploading backup archive to remote storage  ... skipped
Deleting tmp directories ... done
done
done
done
done
done
done
done
Deleting old backups ... skipping
[root@gitlab ~]# ls -lh /var/opt/gitlab/backups/
total 80K
-rw------- 1 git git 80K Sep  3 15:25 1535959505_2018_09_03_11.2.3_gitlab_backup.tar

2.恢復

// 需先停服務unicorn ; stop sidekiq
[root@gitlab ~]# gitlab-ctl stop unicorn      
ok: down: unicorn: 0s, normally up
[root@gitlab ~]# gitlab-ctl stop sidekiq
ok: down: sidekiq: 0s, normally up
// 恢復,BACKUP=後的內容爲備份文件的前綴
[root@gitlab ~]# gitlab-rake gitlab:backup:restore BACKUP=1535959505_2018_09_03_11.2.3
Unpacking backup ... done
Before restoring the database, we will remove all existing
tables to avoid future upgrade problems. Be aware that if you have
custom tables in the GitLab database these tables and all data will be
removed.
...下略...
// 重啓gitlab
[root@gitlab ~]# gitlab-ctl start 
ok: run: alertmanager: (pid 6374) 4967s
ok: run: gitaly: (pid 6388) 4967s
ok: run: gitlab-monitor: (pid 6400) 4966s
ok: run: gitlab-workhorse: (pid 6404) 4966s
ok: run: logrotate: (pid 14710) 1365s
ok: run: nginx: (pid 6435) 4965s
ok: run: node-exporter: (pid 6443) 4965s
ok: run: postgres-exporter: (pid 6450) 4964s
ok: run: postgresql: (pid 6457) 4964s
ok: run: prometheus: (pid 6465) 4964s
ok: run: redis: (pid 6480) 4963s
ok: run: redis-exporter: (pid 6484) 4963s
ok: run: sidekiq: (pid 17350) 1s
ok: run: unicorn: (pid 17359) 0s


十6、擴展

svn命令詳解

http://blog.sina.com.cn/s/blog_963453200101eiuq.html

svn的鉤子

http://coolnull.com/1716.html

gitlab修改端口

http://blog.csdn.net/arybd/article/details/54635295

修改主機名

http://www.mamicode.com/info-detail-1316828.html

第三方郵件

http://blog.csdn.net/liuruiqun/article/details/50000213

server ssh 端口並非22

http://www.cnblogs.com/limx/p/5709101.html

http://www.linuxidc.com/Linux/2017-02/141043.htm

應該修改

/opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
If you use non-standard ssh port you need to specify it
ssh_port: xxxxx

gitlab的鉤子相關配置

http://fighter.blog.51cto.com/1318618/1670667

相關文章
相關標籤/搜索