本地gerrit搭建及使用指南

管理者關注部分

  • 搭建gerrit環境

  •     下載JRE

   Download jre-1.8路徑: https://www.oracle.com/technetwork/java/javase/downloads/index.html

  •     下載gerrit

    wget https://gerrit-releases.storage.googleapis.com/gerrit-3.1.3.war

  •     安裝gerrit

    export GERRIT_SITE=~/gerrit_testsite

    java -jar gerrit-3.1.3.war init --batch --dev -d $GERRIT_SITE

    提示:

            參數    --batch 設置gerrit部分參數爲默認值,安裝一些核心插件等。

                       --dev    配置gerrit服務器使用默認開發選項。

                       --d        配置初始化安裝路徑

    命令執行成功結果:

Generating SSH host key ... rsa(simple)... done

Initialized /home/gerrit/gerrit_testsite

Executing /home/gerrit/gerrit_testsite/bin/gerrit.sh start

Starting Gerrit Code Review: OK

  •     配置文件

    如果搭建起來的gerrit服務器,登陸的時候顯示的是openid。需要獲取openid否則用戶不能創建和登陸。可以將配置文件的auth設置爲如下:

[gerrit]
        basePath = git
        canonicalWebUrl = http://ubuntu:8080/
        serverId = 12b1048a-e444-48d4-9576-90e17bae2b63
[container]
        javaOptions = "-Dflogger.backend_factory=com.google.common.flogger.backend.log4j.Log4jBackendFactory#getInstance"
        javaOptions = "-Dflogger.logging_context=com.google.gerrit.server.logging.LoggingContext#getInstance"
        user = jqh
        javaHome = /usr/lib/jvm/java-8-openjdk-amd64/jre
[index]
        type = lucene
[auth]
        type = DEVELOPMENT_BECOME_ANY_ACCOUNT
[receive]
        enableSignedPush = false
[sendemail]
        smtpServer = localhost
[sshd]
        listenAddress = *:29418
[httpd]
        listenUrl = http://localhost:8080
[cache]
        directory = cache
[plugins]
        allowRemoteAdmin = true

   那麼第一個訪問者成爲管理者,其他訪問者自動成爲用戶的配置。 

 

  • 更新監聽URL

    git config --file $GERRIT_SITE/etc/gerrit.config httpd.listenUrl 'http://localhost:8080'

  •     重啓gerrit服務

    $GERRIT_SITE/bin/gerrit.sh restart

  •     查看gerrit網頁

    http://localhost:8080

    或者http://192.168.1.2:8080/

    第一個訪問的ID將會是管理員賬戶,後面每新登錄一個賬戶,就會創建一個新ID。

  • 創建project

    1、命令創建新倉庫
    shell命令行輸入如下創建新工程:

    ssh -p 29418 [email protected] gerrit create-project hello.git

    其中jqh換成自己的用戶名,如果在其他電腦上,127.0.0.1換成目的ip地址192.168.1.2。

    2、網頁創建新倉庫
    訪問網頁:http://192.168.1.2:8080/

    通過已有用戶名登錄,點擊“BROWSE”----“Repositories”,

    再選擇右邊的"CREATE NEW",即可創建一個默認的倉庫(工程)。

   創建fuchsia_倉庫,示例如下:(其中create initial empty commit選項,false-無commit記錄,true-有初始化commit記錄)

   創建自帶git log記錄的已有倉庫時,請選擇false。我這裏選擇false。

  • 創建已有倉庫,帶log記錄

    1,首先需要在gerrit上創建一個空倉庫不帶日誌記錄的空倉庫。

    方法一:

        如上一步網頁創建新倉庫。

    方法二:

    使用命令行 ssh -p 29418 admin@localhost gerrit create-project fuchsia_.git

    2,然後

    克隆已有倉庫,並進入該目錄

    git clone /home/zeos/fuchsia;cd fuchsia;

    配置gerrit倉庫權限

    git push -o skip-validation ssh://[email protected]:29418/fuchsia_.git *:*

  • 創建分支

    ssh -p 29418 review.example.com gerrit create-branch myproject newbranch master

  • 用戶推送設置

    爲了用戶能夠將修改內容提交推送到本gerrit服務器,需要管理員對該倉庫做如下配置:(其中require change-id in commit messge選擇false)

  • 管理員常用命令

    ssh -p 29418 admin@localhost gerrit xxx

    比如創建項目:ssh -p 29418 admin@localhost gerrit create-project test.git

用戶關注部分

  • 生成public kery

    ssh-keygen -t rsa

    cat ~/.ssh/id_rsa.pub

    將生成的公鑰拷貝到new ssh key框內,然後點擊“ADD NEW SSH KEY”。

  • 克隆倉庫

    同一臺電腦:

    git clone ssh://jqh@localhost:29418/fuchsia.git

    x服務器:

    git clone ssh://[email protected]:29418/fuchsia_.git

    其他用戶克隆的時候,將jqh換成自己用戶名即可。

  • 推送遠程倉庫

    推送前確認自己用戶的git全局配置,主要關注用戶名和郵件,查看全局信息:

    git config --list

  •     配置全局信息:

    git config --global user.name “github’s Name”

  git config --global user.email “[email protected]

  •   配置好之後,開始推送

    git push origin HEAD:refs/for/master

發佈了28 篇原創文章 · 獲贊 9 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章