Gerrit項目管理指南


Gerrit項目管理

前提條件

  • Gerrit系統以及相關插件已成功安裝、配置,可正常運行。

  • 已有Gerrit賬號,並且有管理員權限,有權限才能執行本文所述的各種操作。

  • 本文以3.1.11版為例,不同版本的Gerrit系統,菜單位置和名稱可能略有差異。

創建項目

圖形界面方式

  1. 通過網頁的BROWSE->Repositories進入項目管理頁面;

  2. 點擊右上角的Create New菜單,彈出Create Repository對話框;

  3. 在Repository name對話框中輸入倉名等信息后,點CREATE菜單即可創建成功,其中幾個選項分別是:

    • Repository name,倉名,必填,可以包含/字符、英文大小寫、數字;
    • Rights inherit from,權限集成自,選填,指定已有倉名,默認是All-Projects
    • Owner,選填,指定項目所有者,指定的所有者即便不是管理員也有Review+2等權限;
    • Create initial empty commit,用於指定是否創建一個空提交,默認為True;
    • Only serve as parent for other repositories,用於指定當前倉僅作為Parent倉,默認為False;

命令行界面方式

Gerrit命令行界面的統一使用方式為:

$ ssh -p 29418 $GERRIT_USER@$GERRIT_HOST gerrit sub-cmd

其中,

  • $GERRIT_USER 是具有管理員權限的Gerrit用戶名;
  • $GERRIT_HOST是Geriit系統主機名或IP地址;
  • sub-cmd是具體的gerrit子命令,可以用--help查看;

創建項目的子命令為create-project,具體使用方式可以加--help查看:

$ ssh -p 29418 gerritadmin@localhost gerrit create-project --help
gerrit create-project [NAME] [--] [--branch (-b) BRANCH] [--change-id [TRUE | FALSE | INHERIT]] [--content-merge [TRUE | FALSE | INHERIT]] [--contributor-agreements [TRUE | FALSE | INHERIT]] [--create-new-change-for-all-not-in-target (--ncfa)] [--description (-d) DESCRIPTION] [--empty-commit] [--help (-h)] [--max-object-size-limit VAL] [--new-change-for-all-not-in-target [TRUE | FALSE | INHERIT]] [--owner (-o) GROUP] [--parent (-p) NAME] [--permissions-only] [--plugin-config VAL] [--reject-empty-commit [TRUE | FALSE | INHERIT]] [--require-change-id (--id)] [--signed-off-by [TRUE | FALSE | INHERIT]] [--submit-type (-t) [INHERIT | FAST_FORWARD_ONLY | MERGE_IF_NECESSARY | REBASE_IF_NECESSARY | REBASE_ALWAYS | MERGE_ALWAYS | CHERRY_PICK]] [--suggest-parents (-S)] [--trace] [--trace-id VAL] [--use-content-merge] [--use-contributor-agreements (--ca)] [--use-signed-off-by (--so)]

 NAME                                   : name of project to be created
 --                                     : end of options (default: false)
 --branch (-b) BRANCH                   : initial branch name
                                          (default: master)
 --change-id [TRUE | FALSE | INHERIT]   : if change-id is required (default:
                                          INHERIT)
 --content-merge [TRUE | FALSE |        : allow automatic conflict resolving
 INHERIT]                                 within files (default: INHERIT)
 --contributor-agreements [TRUE |       : if contributor agreement is required
 FALSE | INHERIT]                         (default: INHERIT)
 --create-new-change-for-all-not-in-tar : if a new change will be created for
 get (--ncfa)                             every commit not in target branch
 --description (-d) DESCRIPTION         : description of project (default: )
 --empty-commit                         : to create initial empty commit
                                          (default: false)
 --help (-h)                            : display this help text (default: true)
 --max-object-size-limit VAL            : max Git object size for this project
 --new-change-for-all-not-in-target     : if a new change will be created for
 [TRUE | FALSE | INHERIT]                 every commit not in target branch
                                          (default: INHERIT)
 --owner (-o) GROUP                     : owner(s) of project
 --parent (-p) NAME                     : parent project
 --permissions-only                     : create project for use only as parent
                                          (default: false)
 --plugin-config VAL                    : plugin configuration parameter with
                                          format '<plugin-name>.<parameter-name>
                                          =<value>'
 --reject-empty-commit [TRUE | FALSE |  : if empty commits should be rejected
 INHERIT]                                 on submit (default: INHERIT)
 --require-change-id (--id)             : if change-id is required
 --signed-off-by [TRUE | FALSE |        : if signed-off-by is required
 INHERIT]                                 (default: INHERIT)
 --submit-type (-t) [INHERIT |          : project submit type
 FAST_FORWARD_ONLY | MERGE_IF_NECESSARY    
 | REBASE_IF_NECESSARY | REBASE_ALWAYS     
 | MERGE_ALWAYS | CHERRY_PICK]             
 --suggest-parents (-S)                 : suggest parent candidates, if this
                                          option is used all other options and
                                          arguments are ignored (default: false)
 --trace                                : enable request tracing (default:
                                          false)
 --trace-id VAL                         : trace ID (can only be set if --trace
                                          was set too)
 --use-content-merge                    : allow automatic conflict resolving
                                          within files
 --use-contributor-agreements (--ca)    : if contributor agreement is required
 --use-signed-off-by (--so)             : if signed-off-by is required

其中,

  • --parent和圖形界面的Rights inherit from對應,用於指定權限繼承自哪個倉;
  • --owner 和圖形界面的Owner對應;
  • --empty-commit和圖形界面的Create initial empty commit對應,用於指定是否創建一個空提交;
  • --permissions-only和圖形界面的Only serve as parent for other repositories對應,用於指定當前倉僅作為Parent倉;

創建分支

圖形界面方式

  1. 在Gerrit項目管理界面搜索到項目之后,點擊項目名稱進入某個項目的設置頁面,例如hello-world;
  2. 點擊界面左側的Branches進入分支管理頁面,點擊右上角的CREATE NEW,彈出Create Branch對話框;
  3. 在Create Branch對話框中,輸入分支名點擊CREATE即可創建分支;
    • Branch name,必填,分支名;
    • Initial Revision,選填,版本號,默認是HEAD所指向的版本號;

命令行界面方式

使用gerrit命令的create-branch子命令創建分支,具體參數及使用方式如下:

$ ssh -p 29418 gerritadmin@localhost gerrit create-branch --help
gerrit create-branch PROJECT NAME REVISION [--] [--help (-h)] [--trace] [--trace-id VAL]

 PROJECT        : name of the project
 NAME           : name of branch to be created
 REVISION       : base revision of the new branch
 --             : end of options (default: false)
 --help (-h)    : display this help text (default: true)
 --trace        : enable request tracing (default: false)
 --trace-id VAL : trace ID (can only be set if --trace was set too)

其中,

  • PROJECT對應界面操作中,選擇的項目;
  • NAME對應Branch name,為分支名;
  • REVISION對應Initial Revision,版本號;

git push方式創建分支

管理員權限的用戶可以直接向refs/heads/*推送,refs/heads/*引用是直接和Gerrit倉庫中的分支對應的,不用進行Review流程;

所以,也可以通過git push的方式創建分支,具體操作為:

在代碼倉中執行如下命令:

$ git push origin HEAD:refs/heads/$BRANCH_NAME

其中,$BRANCH_NAME 為具體分支名;

已有項目導入

已有項目的導入,需要對已有項目的所有代碼倉執行如下兩個步驟,分別為:

  1. 創建gerrit代碼倉,可以使用gerrit命令行的create-project子命令進行;
  2. 將已有提交記錄導入gerrit對應代碼倉中,可以對refs/heads/*引用直接使用git push的方式進行;

關於直接推送提交記錄,需要注意的是,

  • Gerrit默認限制了git push一次性推送的提交記錄條數,默認10000條,一次推送的提交記錄數大於該值會導致push失敗;
  • Gerrit默認不允許強制推送(git push--force選項),需要修改All-Projectsrefs/heads/*Push權限后才可以強制推送;

關於強制推送,需要注意的是,

  • 強制推送功允許使用最新的推送覆蓋目標分支上已有的提交記錄,需要謹慎使用;
  • 但是強制推送功能對於分批此推送提交記錄較多的倉非常有用;

提交記錄大於10000條的代碼倉的導入方法

處理思路——分批次提交:

  1. 從最早的提交記錄開始計算;
  2. 將該倉的當前版本指針(HEAD)向后移動5000條提交記錄;
  3. 進行一次push,如果push成功則重復執行第2步;否則,執行報錯並結束推送過程;

成員權限管理

Gerrit支持多種方式的權限管理方式:

  • 項目默認權限(All-Projects)設置
    • 項目權限繼承
    • All-Projects是新項目的默認繼承項目(不指定parent)
  • 單個項目的權限管理
    • 單個項目也可以設置每一種權限允許的范圍
    • 允許范圍是以組(Group)為單位的
    • 權限可以被其他項目繼承,但是不要刪除它
  • 組(Group)管理
    • 管理員可以創建組,沒有刪除界面(圖形和命令都沒有)
    • 管理員和組Owner可以管理組成員(Memebers)
    • 一個組可以添加多個成員
    • 一個成員可以屬於多個組


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM