Gitlab使用手冊資料_第1頁
Gitlab使用手冊資料_第2頁
Gitlab使用手冊資料_第3頁
Gitlab使用手冊資料_第4頁
Gitlab使用手冊資料_第5頁
已閱讀5頁,還剩18頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

Gitlab使用手冊

目錄

-Gitlab賬號/庫申請流程2

l.lGitlab賬號2

1.2Gitlab‘I’巾j3

二Gitlab登錄3

2.2Gitlab登錄頁面3

--Git環(huán)?境/□圖(fw罟.r-i?????????????????????????????????????????????????????????????????????????.3

3.1創(chuàng)建公鑰4

3,1.1Linuxi,?4

3.1.2Windows環(huán)境4

3.1.3MacOS環(huán)境8

3.2G出abSSH頁面配置8

Git操作命令..9

4.1Git本地倉庫操作命令9

4.1.1gitinit/gitclone初始化庫10

4.1.2gitstatus查看狀態(tài)…“11

4.1.3gitadd添加文件12

4.1.4gitdiff對比文件12

4.1.5gitcommit提交更新13

4,L6gitrm彳多.乂f~|一13

4.1.7gitmv移動文件14

4.1.8gitlog,,,,,,,,,*,,,i?,,,,,,i?,,,i,ii,,,,,,i,,,,,i?i,,i,,,,,,ti,i,,,,,,,i,,,,,,,,,,,,,,,i,,,,,*i,*,,,,,,i?i,,i,,,,,,,i,i,、,*,,,i,,,,,,,,,,,,,,15

4.1.9gitreset撤銷操作15

4.1.10gitbranch創(chuàng)建分支

4.1.11gitmerge分支合并18

4.1.12gitconflictJ:f中:”,“”“i,“““““““““””“1“,””“18

4.1.13gittag創(chuàng)建標(biāo)簽19

4.2Git遠(yuǎn)程倉庫關(guān)聯(lián)操作命令.20

4.2.1gitremote查看遠(yuǎn)處倉庫20

4.2.2gitremoteshow查看遠(yuǎn)程倉庫信息21

4.2.3gitremoteadd添加遠(yuǎn)程倉庫21

4.2.4gitfetch倉(據(jù).““““21

4.2.5gitpull獲取最新版本22

4.2.6gitpush推據(jù)到程*1^庫”22

4.2.7gitremoterename/rm遠(yuǎn)程倉庫重命名/刪除22

?fiWindowsGit操作23

-Gitlab賬號/庫申請流程

1,1Gitlab賬號

使用郵箱前綴、郵箱密碼訪問即可。

1.2Gitlab庫申請

郵件申請。(發(fā)郵件給zhaoweiz@、cuixfl@)

二Gitlab登錄

2.1Gitlab訪問路徑

URL:http://3/

2.2Gitlab登錄頁面

Existinguser?Signin

[LDAP]

Standard

LDAPSignin

=Git環(huán)境配置

3.1創(chuàng)建公鑰

不同操作系統(tǒng)創(chuàng)建公鑰的方式不同。以下是三種操作系統(tǒng)的舉例。

3.1.1Linux環(huán)境

$ssh-keygen〃訊公鑰

$cat"ssh/idjsa.pub〃將公鑰文件內(nèi)容拷貝到Gitlab配置頁面中。見3,2節(jié)。

注意:Vim文件復(fù)制粘貼可能會導(dǎo)致內(nèi)容換行,導(dǎo)致公鑰無效。

3.1.2Windows環(huán)境

需要下載msysgit和tortoisegit客戶端

第一步,下載msysg讓并安裝.(基本上一路Next。因為我們還要安裝tortoisegit,所

以不需要選擇"Windowsexplorerintegration"°)

URL:

https;〃/p/msysgit/downloads/list?can=2&q=%22Full+installe「+

for+official+Git+for+Wirdows%22

或者公司共享目錄:\\devshare\工具共享、常用軟件\qit

第二步,下載tortoisegit并安裝

URL:

https:〃/p/tortoiseq讓/wiki/Download?tm=2

或者公司共享目錄:\\devsha「代工具共享'常用軟件\qit

第三步,在tortoisegit上配置msysgit的路徑(見下圖)

Settings-TortoiseGit

創(chuàng)建公鑰的方式(二者選一即可)

(1)通過9代曲@6讓方式生成公鑰

a)從Windows開始菜單選擇TortoiseGit,點擊其下的Puttygen工具,該工具用于生

成Putty支持的SSH密匙對。

TortoiseGit

斜Help

0Notepad2

.Pageant

PuttygerT^

Settings

kTortoiseGitBlame

E&TortoiseGitIDiff

itTortoiseGrtMerae

b)點擊Generate按鈕,即生成公鑰和私鑰。將Publickey(公匙)ffiPrivatekey(私

匙)都保存到文檔中,以免丟失。其中Privatekey是你的TortoiseGit用來驗證用戶身份,

呼PuTTYKeyGenerator

說明:

L生成key的類型:SSH-2RSA

說明:

1.將生成的Publicke汴占貼到GitLab站點”申請者帳號"里。配置方式見32節(jié)。(由

于tortoisegit生成的公鑰粘貼到’gitlabSSHKey'中并不能夠自前生成’title',因此

需要自己填寫一個‘title')

WI皿

AddanSSHKey

£A

K?yithm

2.保存"Saveprivatekey"到本地。

(2)通過命令行方式生成公鑰

a)點擊‘開始’,在搜索中輸入‘cmd'。

b)$ssh-keygen//生成公鑰

c)將生成的Publickey粘貼到GitLab站點“申請者帳號"里。配置方式見3.2節(jié)。

3.1.3MacOS環(huán)境

$ssh-keygen〃淑公鑰

$cat-/.ssh/id_rsa.pub〃符公鑰文件內(nèi)容拷貝到Gitlab配置頁面中。見3.2節(jié)。

3.2GitlabSSH頁面配置

Gitlab"AddSSHKey"界面如下:

學(xué)ProMsOlMMq

.—PsuwsHMAeMnS$HKiy?1

MySSHkeys

BHMywcon3Nm591kfyywXu第”酬?

88HKfr>(1)

皿ehMo>gJ27PCW%N6%a%騙和&&?£■H/?81???<12%”

將3.1節(jié)創(chuàng)建的公鑰拷貝到"Key"方框中:

AddanSSHKey

r?t

Kw)^WtywpvtKMyhrt—"mF>??prl除F即

Add%

四Git操作命令

4.1Git本地倉庫操作命令

?gitinit/gitclone【嫄化庫】

?gitstatus【查看狀態(tài)】

?gitadd【添加文件】

?gitdiff【對匕應(yīng)件】

?gitcommit【提交更新】

?gitrm【移除文件】

?gitmv【移動文件】

?gitlog【查看提交歷史】

?gitreset【撤銷操作】

?gitbranch【創(chuàng)建分支】

?gitmerge【分支合并】

?gitconflict【解決沖突】

?gittag【創(chuàng)建標(biāo)簽】

4.1.1gitinit/gitclone初始化庫

>初始化一個新庫

$gitinit

>從現(xiàn)有倉庫克隆

$gitcloneURL

4.1.2gitstatus查看狀態(tài)

>若沒有可跟蹤的文件,用gitstatus命令,則會輸出:

[root@vmll020031testlOO6]#gitstatus

#onbranchmaster?

#

#initialcommit

#

nothingtocommit(create/copyfilesanduseHgitadd"totrack)

>若編輯T新文件hi.txt,保存退出。用gitadd命令跟蹤文件后運行g(shù)itstatus命

令,則輸出:

r

troor@vmll020031TesriOO61#gitaddhi.rxr

*roor?vmll020031restlOOGj#gitstatus

#onbranchmaster

#

#initialcomm-it

#

#Changestobecommitted;

*(use"gitrm-一cached<fitounstage)

#

#newfile:hl.txt

說明:只要在"Changestobecommitted"下面,就表示為已暫存狀態(tài)°

>若修改已經(jīng)暫存狀態(tài)的文件,保存退出后用gitstatus命令,則會輸出:

[rootevmll020031testlOOO]#gitstatus.

#Ortbranchmaster

#.Initialcommit

*changestobecommitted;

#(use"g1rrm--cachedtounstage)

,newfile:hi.txt

%

*Change%notntagedforcommit:

?'fuse"gitaddtoupdatewhatwillbecommitted)

#<useMgixcheckout--<f1le>...Mtodiscardchanges1nworkingdirectory)

*modified;hi.rxt

說明:hi.txt文件出現(xiàn)了兩次!一次算未暫存,一次算已暫存。需要將未暫存的文件

通過gitadd添加到已暫存。

4.1.3gitadd添加文件

作用:

可以用它開始跟蹤新文件;

把已經(jīng)跟蹤的文件放到暫存區(qū)

合并時把有沖突的文件標(biāo)記為已解決狀態(tài)。

4.1.4gitdiff對比文件

作用:

當(dāng)前作的哪些更新還沒有暫存;

有哪些更新已經(jīng)暫存起來準(zhǔn)備好了下次提交。

[root@vmll020031testlOOGJ*gitdiff

diff--gira/hi.rxrb/hi.txr

■index19Oal8O..c25aO2b100644

a/hi.txr

+++b/hi.Txt

?-1+1.2?

123

+35d

[root?vmii020031testiooci#g1taddM.txt

[root@vmi:L02003iSETIOOS]#gitcHfJ

說明:

有時候一下子暫存了所有更新過的文件后,運行g(shù)it.diff后卻什么也沒有。原因是,

gkdiff僅顯示還沒有暫存起來的改動,而不是這次工作和上次提交之間的差異。

4.1.5gitcommit提交更新

在提交之前,一定要用gitstatus確認(rèn)還有哪些修改過的或是新建的文件還沒有暫存

起來。否則,這些沒有暫存的文件就不能將最新變化提交到版本庫中。

參數(shù)介紹:

gitcommit-m使用-m參數(shù)后跟提交說明的方式,在一行命令中提交更新

[root@vmll020031testl006]#gitcommit-m"test"h~i.txt

[master(root-commit)Ic4a7eb]test

1filechanged,2insertions(+)

createmode100644hi.txt

gitcommit-a自動把所有已經(jīng)跟蹤過的文件暫存起來一悔交,跳過使用暫存區(qū)域

提交更新

ItvjtaiiyuncruvrcuLUK.MIIIIIIIL\UNUyiLCTCTOCUIU/uiu

[root@vmll020031testl006]#gitcommit-a-m"test"

[masterd72648e]rest

2fileschanged,4deletions(-)

deletemode100644hi.txt

deletemode100644test.txt

4.1.6gitrm移除文件

刪除已提交的某個文件,需要先用gitrm命令從暫存區(qū)域中移除這個文件,然后再用

gitcommit命令提交。

rio^ri11IQuoniiTiiL^worKIriu415ytied”,

[roQt@vinll020031testl006j#11

total0

-rw-r??r?-1rootroot0Nov615:15test.txt

[root@vmll020031testl006]#gitstatus

#onbranchmaster?

nothingtocommit(workingdirectoryclean)

[root@vmll020031testl006Jfgitrmtest.txt

rm'test.txt'?

[root@vmll020031testl006]#gitstatus

#onbranchmasterA

#changestobecommirted:

#(use"gitresetHEAD"tounstage)

deleted:test.txt

rroot@vmll020031testl006]#gitcommittest.txt-m-del"

[masxerb7d24ab]del

0fileschanged

deletemode100644test.txt

[root(&vmll020031testl006]#gitstatus

#onbranchmaster

nothingtocommitdirectoryclean)

41.7gitmv移動文件

Git中的重命名某個文件,倉庫中存儲的元數(shù)據(jù)并不會體現(xiàn)出這是一次改名操作。

文件改名并查看當(dāng)前狀態(tài);

root@vmll020031restlOObmvtesr.txrtest_to.txt

root@vmll020031testl006ST3TCTJ5

onbranchmaster

changestobecommitted

(use"gitresetHEAD??"tounstage)

renamed:tQsr.txt->testro.txt

運行g(shù)itmv就相當(dāng)于運行了下面三條命令:

$mvtest_from.txttest_to.txt

$gitrmtest_from.txt

$gitaddtest_to.txt

4.1.8gitlog查看提交歷史

每次更新都有一個SHA-1校驗和、作者的名字和電子郵件地址、提交時間,最后縮

進(jìn)一個段落顯示提交說明。

[root@vmll020031testl006]#gitlog

commir055430106951c9794b967c75a2f6213do3da2515

Author:zhaowei3<zhaowei3@staff.si>

Date:TueNov614:48:592012+0800

committest

commitlc4a7e601293e3f97e654929a803d67f256e8b34

Author:zhaowei3<zhaowei3d5taff.>

Date:TueNov614:38:132012+0800

test

常用查找歷史日志的選項:

-P:項展開顯示每次提交的內(nèi)容差異;

-n(數(shù)字):僅顯示最近的n次更新。

在做代碼審查,或者要快速瀏覽其他協(xié)作者提交的更新都作了哪些改動時,就可以用

這個選項9

4.1.9gitreset撤銷操作

》取消已暫存的文件

若不小將某個文件添加/刪除到了暫存區(qū)域,可以用"gitresetHEAD<file>,,,“命

令取消暫存.

rrootdvmil020031testlOOfili1gitaddhLtxt

[rQQt&vmllO2OO31testl006]fgitstatus

#Onbranchnaster

#Changestobecommitted:

#(use"gitresetHEADtounstage)

*

#modified:hi.txt

#

[rooi?vmll020031testl006]#gitresetHEADhi.txt

unstagedchangesafterreset;?

Mhi.txt

[rootevmll020031testiooe]#g1tstatus

#onbranchmaster?

#changesnotsragedforcommit:

#(use"gitadd<file>..toupdarewhatwillbecommitted)

#(use"gitcheckout--."todiscardchangesinworkingdirectory)

.

#modified!hi.txt

nochangesaddedtocommit(use"gitadd"and/or"gitcommit-a")

>修改最后一次提交

提交后發(fā)現(xiàn)漏掉了一些文件想要撤銷剛才的提交6若剛才提交完后沒有做任何改動,

可以使用一amend選項重新提交,

[root?v?ii02003itestiooej#gitstatus

9onbranchBaster?

fChangestobecoral“ed;

?(use"altresetHEADtounstag?)

,

*modified;hi.txt

?

fro?^v?11020031testlOOfi]#gftcoomit-m4firstcoanfttest,secondcomiithi"test.txv

[masterMeblbf]firstCownitiOwnithi

1filechanged.1insertion。)

[root?v?11020031testlOOfij#gitstatus

#Onbranchvaster?

?Changestobeconwitted:

“(use"gitresetHEADtounstage)

#

#modified:hi.txt

#

[roQt?vBil020031testlOOfi]#gitcomit--anendhi.txt快

firstcomnlttest.secondcoamithl

?Pleaseenterthecoraltnessageforyourchanges.Linesstarting

*withwillbeignored,andanemptyliessageabortstheconmlt.

tExplicitpathsspecifiedwithout-inor*o:assuming--onlypaths...

#Qnbranch

?changestobecoraHtted:

#(use"gkresetHEADAItounstage)

#modified:M.txt

■modified:test.txt

>取消工作目錄中已經(jīng)修改的文件

若已經(jīng)添加到暫存區(qū)域的文件又進(jìn)行了修改,但這些改動又覺得是沒有必要,則可以

用Hgitcheckout-<file>./恢復(fù)到修改前的版本。

Ill*\八tAL|,<EItty”

[root@vmll020021testl006]#gitstatus

#onbranchmaster——?

#Changestobecommitted:

#(use"gitresetHEAD<file>..."tounstage)

#modified:hi.txt

#

#Changesnotstagedforcommit:

■(use"gitadd<file>...*'toupdatewhatwillbecommitted)

#(use"gitcheckout—<f1le>.todiscardchangesinworld

#

#modified:hi.txt

$vimhi.txt

*iI?LAk.NmFtlILL匕II

[root@vmll020031resri006]#gitcheckout--hi.txt

[root?vmll020031testl006]tfgitstatus

#onbranchmaster____________?

#changesiobecowiltted:

?(use"gitresetHEADtounstage)

#modified:hl.txt

4.1.10gitbranch創(chuàng)建分支

創(chuàng)建一個test分支,然后將目錄切換到test分支下面。

[root@vmll020031testlOOSJ#gitbranch

*master

[root@vmll020031testl006]#gitbranchprol

[roox?vmll020031tesxiOO6]#Drancn

,waste尸]—―?

prol

[root<?vmllQ20031testl006]*gitcheckout£rol.

Switchedtobranch'prol'

[root@vmll020031testlOO6]#gitbranch

maste『?

*proi_________________________________________

注意:test分支前的〃*〃字符:表示當(dāng)前所在的分支。

gitcheckout-b分支名

相當(dāng)于:

gitbranch分支名

gitcheckout分支名

4.1.11gitmerge分支合并

首先查看當(dāng)前目錄所有分支清單,然后切換到master分支目錄下,最后將prol分支

內(nèi)容合并到master上。

[root?vmll020621testl006]#gitcheckoutmaster

Switchedtobranch'master'

[root?vmll020031testlOO6J#gitbranch

*master

prol

[root@vmll020031testlOOGj#gitmergeprol

updating90af0bl..33b41d9

Fast-forward

hi.txt|1+

test.txtI1+

Wcgw*21丑£085(+)

4.1.12gitconflict解決沖突

>如果修改了兩個待合并的分支里同一個文件的同一個部分,則會出現(xiàn)如下報錯:

[root@vmll020031testl006]#gitmergeprol

Auto-mergingtest.txt

CONFLICT(content):Mergeconflictintest.txt

Automaticmergefailed;fixconflictsandthencommittheresult.

「-c——YYcrcWr..cclIj1J

Crcx)c<?vnil1020031tostlOO6J#g1xstatus

?Onbranchmaster

?vouhav?urvMraodpaThs.

*《『Txcoo4Plccsandrun"gdtucmmlt”〉

?unmcrgcdpaths;

.(UGQ"glradd<T11o>..."tomarkrofiolur1on)

*boxhmodiad:COST.rxc

>如何編輯沖突:

首先查看當(dāng)前目錄下的狀態(tài)(gitstatus),然后編輯沖突文件Wimtest.txt),再將沖突

文件置為解決狀態(tài)(gitaddtest.txt),最后將合并的文件提交給(gitcommit-m"注釋〃)。

沖突文件test.txt,打開后可以看到:

<<<<<<<HEAD

bral-11111222

bral-qwerea

>>>>>>>prol

說明:二二二二二二二隔開的上半部分,是HEAD(即master分支)中的內(nèi)容,下半部

分是在test分支中的內(nèi)容。

4113gittag創(chuàng)建標(biāo)簽

>列出所有標(biāo)簽

gittag

>搜索標(biāo)簽

gittag-I標(biāo)簽名

>創(chuàng)建標(biāo)簽

gittag-a標(biāo)簽名-m注釋

4.2Git遠(yuǎn)程倉庫關(guān)聯(lián)操作命令

gitremote【查看遠(yuǎn)處倉庫】

■gitremoteshow【查看遠(yuǎn)程倉庫信息】

gitremoteadd【添加遠(yuǎn)程倉庫】

gitfetch【從遠(yuǎn)程倉庫抓數(shù)據(jù)】

gitpull【安取最新版本】

gitpush【推送數(shù)據(jù)到遠(yuǎn)程倉庫】

■gitremoterename/rm【遠(yuǎn)程倉庫重命名/刪除】

4.2.1gitremote查看遠(yuǎn)處倉庫

用gitremote命令,查看當(dāng)前配置有哪些遠(yuǎn)程倉庫。加上參數(shù),可以列出所有的

遠(yuǎn)程倉庫。

[root§vmll020031mysite]#gitremote

origin

[root@vmll020031mysite]#gitremote-v)

originhttps://github.coni/zhaoweil017/iiy$ite.git(fetch)

originhttps://github.coni/zhaowGilOlZ/mysite.git(push)

「Rd——“"ccccx_Un_______________________________

參數(shù)介紹;

-V:可以列出所有的遠(yuǎn)程倉庫。

4.2.2gitremoteshow查看遠(yuǎn)程倉庫信息

11

yy"_,,…m丁'J,=,,.:u,,'■",,3,,j'=/,,,j」'…7‘、—

[root@vmll020031mysite]#gitremoteshow

origin

[root@vmll020031mysite]#gitremoteshoworigin

*remoteorigin

FetchURL:/zhaoweilOlZ/mysite.git

PushURL:/zhaoweil017/mysite.git

HEADbranch:master

Remotebranches;

masrertracked

sinatracked

Localbranchconfiguredfor'gitpull':

mastermergeswithremotemaster

Localrefconfiguredfor'gitpush':

masterpushesto.magte匚(uptodate)

4.2.3gitremoteadd添加遠(yuǎn)程倉庫

若要添加Y新的遠(yuǎn)程倉庫,運行g(shù)itremoteadd[shortname][url]

UiIIIIIULpb.//yILIIUU.LUiil/IXUX//UiyjILt!,yIL

rroot9vmll020031aysitel#gitreaoteaddprojectl/zhaoweil017/Bysite.qitfe

[root@vmll020031iiysitejfgitreaote-v

originhttps://g1thub.coa/zhaowei1017/ayrite.git(fetch)

originhttps://Q1thub.com/zhaowei1017/mysite.git(push)

project!https://gkhub.coni/zhaoweil017/Bysite.git(fetch)

projectlhttps://github.com/zhaoweilOV/Bysite.git(push)

4.2.4gitfetch從遠(yuǎn)程倉庫抓數(shù)據(jù)

命令:$gitfetchproname

【root@vml1020031噸site”里tremote二vJ

originhttps://g1thub.coffl/2haowe1l0l7/llfys1te.gitCfetch)

originhrtps:///2haowe1l0l7/mysite.g1t(push)

projectlnttps:///zhaoweil017/mysite.git(fetch)

projectlhttps;///zhaoweil017/mysite.git(push)

[root?vmil020031nrysite]#qitfn比project人

Fromhttps://g1chub.cow/zhaoweflfflT福>

*[newbranch]master->projectl/master

*[newbranch]s1na->projectl/sina

4.2.5gitpull獲取最新版本

[root?vmll020031mysite]*gitpullorigin

Fromhttps://qithuD.com/zhaoweil017/mysite

bfa6030..dfO34c7master->origin/master

Alreadyup-to-date.

426gitpush推送數(shù)據(jù)到遠(yuǎn)程倉庫

如果要把本地的內(nèi)容推送到Git服務(wù)器maste分支上

命令:$gitpushoriginmaster

[rootfflvmll020031mysite]#qiiaddzpf.txt.

[rootfflvmll020031mysite]#git-cbmmTr-m"d

[masterdfO24c7]ci

1filechanged,1insertion(+)

[root@vmll0206031mysite]#gitpushprojectlmaster

Usernameforhttps://github.com':

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論