简体   繁体   English

将仓库从 git 导入到 gerrit

[英]Import repository from git to gerrit

I have two questions about Gerrit:我有两个关于 Gerrit 的问题:

  1. How do I convert or import an already existing Git repository into Gerrit's format?如何将已经存在的 Git 存储库转换或导入 Gerrit 的格式? There were a lot of commits without Gerrit control, I want to simply push those commits into a Gerrit project.有很多没有 Gerrit 控制的提交,我想简单地将这些提交推送到 Gerrit 项目中。

    I see two ways to do it:我看到了两种方法:

    1. Copy existing bare Git directory to Gerrit and then add it to database.将现有的裸 Git 目录复制到 Gerrit,然后将其添加到数据库中。 Is that a safe method?这是一种安全的方法吗?

    2. Push all commits from my local repository to gerrit repository.将所有提交从我的本地存储库推送到 gerrit 存储库。

  2. How to revert repository from Gerrit to original Git format?如何将存储库从 Gerrit 恢复为原始 Git 格式? Is it required to remove Gerrit's special */for/* branches to do that?是否需要删除 Gerrit 的特殊*/for/*分支才能做到这一点?

First of all: There is no special "Gerrit format".首先:没有特殊的“Gerrit 格式”。 Gerrit works with regular git repositories. Gerrit 使用常规 git 存储库。

  1. Create a new project in Gerrit (without an initial commit).在 Gerrit 中创建一个新项目(没有初始提交)。 Add the created repository as a remote to your existing repository and simply push.将创建的存储库作为远程添加到您现有的存储库,然后简单地推送。 You can configure Gerrit to allow direct pushing into the repository (bypassing review), allowing you to import the entire repository.您可以配置 Gerrit 以允许直接推送到存储库(绕过审查),从而允许您导入整个存储库。

    Alternatively, if you have direct access to Gerrit's repository location (eg via SSH or on the local filesystem), you can just push directly into the repository (whereever Gerrit created it), bypassing Gerrit entirely.或者,如果您可以直接访问 Gerrit 的存储库位置(例如,通过 SSH 或在本地文件系统上),您可以直接推送到存储库(无论 Gerrit 创建它的地方),完全绕过 Gerrit。 You'll need to flush the Gerrit caches afterwards, however, for Gerrit to notice that the repository HEADs have updated.但是,您需要在之后刷新 Gerrit 缓存,以便 Gerrit 注意到存储库 HEAD 已更新。

  2. As said, there is no "Gerrit format".如前所述,没有“Gerrit 格式”。 Just clone your repository from gerrit, and all is well.只需从 gerrit 克隆您的存储库,一切都很好。 You don't need to worry about any special branches.您无需担心任何特殊分支。

I imported many GIT projects to gerrit, the easiest way I found was to copy the xy.git Directory of the git repository to the directory where gerrit deposits the git repos.我在gerrit中导入了很多GIT项目,我找到的最简单的方法是将git仓库的xy.git目录复制到gerrit存放git仓库的目录下。 After restart of gerrit process the new project is in the list of new projects and you can edit description and access rights.重新启动gerrit 进程后,新项目在新项目列表中,您可以编辑描述和访问权限。

  1. Just create the new project in Gerrit, and then push the git repository there.只需在 Gerrit 中创建新项目,然后将 git 存储库推送到那里。 If you want to bypass review, push directly to master instead of refs/for/master.如果你想绕过审查,直接推送到 master 而不是 refs/for/master。 You'll need to add the permission to do this to yourself.您需要为自己添加权限才能执行此操作。

    I think the error message may be caused by you not having imported your ssh key to Gerrit yet.我认为该错误消息可能是由于您尚未将 ssh 密钥导入 Gerrit 造成的。

  2. Just clone the repository from Gerrit.只需从 Gerrit 克隆存储库。 It won't include any extra branches.它不会包括任何额外的分支。

Additional information...附加信息...

So you can copy the git repository straight across into the gerrit data location and it will show up after a restart ( or flush of cache ( reindex )).因此,您可以将 git 存储库直接复制到 gerrit 数据位置,它会在重新启动(或刷新缓存( reindex ))后显示。

BUT you will be missing the important configuration from your repository, which may prevent ability to push, create branches, review etc.但是您将丢失存储库中的重要配置,这可能会阻止推送、创建分支、审查等的能力。

If you view the repo you will see it is missing the 'refs/meta/config' branch.如果您查看 repo,您​​会发现它缺少“refs/meta/config”分支。 So in an normal system without changes this will inherit from All-Projects, but this could be any Project on your configuration.因此,在没有更改的普通系统中,这将从 All-Projects 继承,但这可以是您配置中的任何项目。

Steps to fix configuration:修复配置的步骤:

  1. List item项目清单
  2. Copy git repo复制 git 仓库
  3. Refresh cache / restart gerrit / reindex刷新缓存/重启gerrit/reindex
  4. Open repo from project list view从项目列表视图打开 repo
  5. Click on branches点击分行
  6. Type in the new branch name of "refs/meta/config" at revision "HEAD"在修订版“HEAD”处输入“refs/meta/config”的新分支名称
  7. Click "edit config" from the project general view.从项目总视图中单击“编辑配置”。
  8. This creates a file (project.config) in this branch for configuration.这将在此分支中创建一个文件 (project.config) 以进行配置。 Add some default configuration, either taken from a working repo, or as follows:添加一些默认配置,或者从工作仓库中获取,或者如下:

eg例如

[access]
   inheritFrom = All-Projects
  1. Click Save, then CLOSE.单击保存,然后关闭。
  2. Click Review ( to give it +2)点击评论(给它+2)
  3. Click Publish Edit to save this change into gerrit.单击 Publish Edit 将此更改保存到 gerrit 中。

You can now use the repository with sensible inherited configuration the same as your other projects.您现在可以像其他项目一样使用具有合理继承配置的存储库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM