在伺服器端將現有Git專案匯入GitLab

2022-01-14 18:20:40 字數 1690 閱讀 6774

gitlab是由ruby語言開發的基於linux的git伺服器,是我見過的最強大的git伺服器。發現它之後,立即決定將git伺服器換成gitlab。

但安裝好gitlab之後面臨乙個問題,如何將伺服器上的git專案直接匯入到gitlab,之前的git伺服器是由是git+apache搭建的(詳見在linux上用apache搭建git伺服器)。

在網上發現了這篇文件——import bare repositories into your gitlab instance,並按之進行了操作。

1)設定存放**庫的主目錄

vi /etc/gitlab/gitlab.rb

比如這裡設定為:git_data_dir "/gitlab/repos"

2)訪問剛搭建的gitlab站點,建立乙個group,比如cnblogs。

這時會在 /gitlab/repos 下建立 /gitlab/repos/repositories/cnblogs 資料夾。

然後在/gitlab/repos/repositories/建立乙個資料夾,比如cnblogs

3)將現有的所有git專案檔案複製到這個資料夾

cp -r /data/git/* /gitlab/repos/repositories/cnblogs

4)修改一下複製過來的資料夾的所有者:

chown -r git:git /gitlab/repos/repositories/cnblogs

5)執行gitlab匯入命令

cd /var/opt/gitlab

gitlab-rake gitlab:import:repos

等了一段時間之後,顯示done,卻乙個專案也沒匯入進來。

經研究發現,在匯入時,gitlab只認資料夾名以.git結尾的專案。於是,將要匯入的專案資料夾名稱加上.git字尾,再次進行匯入。

結果顯示匯入成功,比如:

processing cnblogs/cnblogsjob.git

* created cnblogsjob (cnblogs/cnblogsjob.git)

done!

可以是gitlab站點上卻看不到已匯入的專案。多次努力,也沒能解決這個問題。

後來,實在沒辦法,改為手動匯入,匯入方法如下:

1)在gitlab站點上建立與要匯入的專案同名的專案。

2)進入剛建立的專案資料夾

cd /gitlab/repos/repositories/cnblogs/專案名稱.git

3)刪除該檔案下的所有檔案

rm -rf *

4)將要匯入的專案資料夾下的所有檔案複製過來

cp -r /data/git/cnblogsjob/* /gitlab/repos/repositories/cnblogs/cnblogsjob.git

就這樣將專案乙個乙個地匯入進來。

5)匯入完成後,修改一下匯入的所有專案的檔案所有者

chown -r git:git /gitlab/repos/repositories/cnblogs

如果不修改所有者,客戶端無法進行git push。

就這樣手動地完成了現有git專案的匯入。

備註:作業系統是centos 6.2,gitlab版本是7.8.4。

在伺服器端將現有Git專案匯入GitLab

gitlab是由ruby語言開發的基於linux的git伺服器,是我見過的最強大的git伺服器。發現它之後,立即決定將git伺服器換成gitlab。但安裝好gitlab之後面臨乙個問題,如何將伺服器上的git專案直接匯入到gitlab,之前的git伺服器是由是git apache搭建的 詳見在lin...

git伺服器端建立專案

cd myproject 你建立的專案資料夾 git init 執行git的本地初始化 git add 將所有的檔案新增到版本控制系統 git commit m initial commit 在本地提交到版本庫 git remote add origin git 116.255.160.144 sr...

在centos5 git伺服器端安裝

最近需要自己開發專案和好 一起發所以就搭建了這個git伺服器端安裝。我在網上搜了一些網頁應該有用的,希望給你們一些幫助 這個裡面比較詳細 安裝git伺服器其實即使安裝2個東西乙個是git還有乙個就是他的許可權管理。前者安裝沒問題,但是在setuptools時候出現了乙個錯誤問題,importerro...