git 在 Gitlab 实例之间迁移 repos

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19110423/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 09:08:23  来源:igfitidea点击:

Migrate repos between instances of Gitlab

linuxgitmigrationrepositorygitlab

提问by Bj?rn Otto Vasbotten

Due to my old installation of Gitlab being too difficult to upgrade (Thread on TKL support forums: http://www.turnkeylinux.org/forum/support/20120913/upgrading-gitlab), I have downloaded the current TKL Gitlab distro, and followed Gitlabs standard upgrade path so that I now have a fully upgraded Gitlab 6.1 installation running with TKLBAM and all that good stuff. So far so good.

由于我旧的 Gitlab 安装太难升级(TKL 支持论坛上的主题:http: //www.turnkeylinux.org/forum/support/20120913/upgrading-gitlab),我已经下载了当前的 TKL Gitlab 发行版,并且遵循 Gitlabs 标准升级路径,以便我现在拥有一个运行 TKLBAM 和所有好东西的完全升级的 Gitlab 6.1 安装。到现在为止还挺好。

But, it turns out that our old version of gitlab does not give HTTP urls to repos, so that means that I can't use the "Import existing repository" function in Gitlab 6.1

但是,事实证明我们旧版本的 gitlab 没有给 repos 提供 HTTP url,所以这意味着我不能在 Gitlab 6.1 中使用“导入现有存储库”功能

I know that i can simply copy the old Git repositories from the old VM to the new one, but how can I make these repositories visible in Gitlab on the new VM?

我知道我可以简单地将旧的 Git 存储库从旧的 VM 复制到新的存储库,但是如何使这些存储库在新 VM 上的 Gitlab 中可见?

采纳答案by ChrisA

One option would be to:

一种选择是:

  1. Clone the old repo from gitlab onto a dev machine.
  2. Create a blank repo on the new gitlab.
  3. Add the new repo as a remote on the dev machine.
  4. Push everything back to the new repo.
  5. Remove the old repo from remote repos list.
  1. 将旧的 repo 从 gitlab 克隆到开发机器上。
  2. 在新的 gitlab 上创建一个空白的 repo。
  3. 添加新的 repo 作为开发机器上的远程。
  4. 将所有内容推回到新的回购中。
  5. 从远程仓库列表中删除旧仓库。

To create a remote called newRepo, do: git remote add newRepo gitlab.localhost.com:User/newRepo.git(replace the url on the end with the one for your repo)

要创建一个名为 newRepo 的遥控器,请执行以下操作:(git remote add newRepo gitlab.localhost.com:User/newRepo.git将末尾的 url 替换为您的 repo 的 URL)

回答by redhot

I recently migrated from gitolite to gitlab and the official rake task gitlab:import:reposworked for me. I am using gitlab 6.1.0 (82f3446). Here is what I did:

我最近从 gitolite 迁移到了 gitlab,官方 rake 任务gitlab:import:repos对我有用。我正在使用 gitlab 6.1.0 (82f3446)。这是我所做的:

  • rsyncbare repos from gitolite to repositories/{group}/. Make sure to replace {repository}with the name of the gitolite repo, and change the hostname of your gitlab server.

    rsync -rth --progress repositories/{repository}.git \
    git@gitlab-server:/home/git/repositories/{group}/
    

    Here, {group}is the name of the user group you want the repository to be added to. If you don't have any specific group, choose rootas the group name.

  • Fix permissions – only necessary when the rsyncuser is not git:

    sudo chown -R git:git repositories/{group}/
    
  • cd ~/gitlab

  • Run the rake task to import all new repositories:

    bundle exec rake gitlab:import:repos RAILS_ENV=production
    
  • rsync从 gitolite 到repositories/{group}/. 确保替换{repository}为 gitolite 存储库的名称,并更改 gitlab 服务器的主机名。

    rsync -rth --progress repositories/{repository}.git \
    git@gitlab-server:/home/git/repositories/{group}/
    

    此处{group}是您希望将存储库添加到的用户组的名称。如果您没有任何特定组,请选择root作为组名。

  • 修复权限 - 仅当rsync用户不是时才需要git

    sudo chown -R git:git repositories/{group}/
    
  • cd ~/gitlab

  • 运行 rake 任务以导入所有新存储库:

    bundle exec rake gitlab:import:repos RAILS_ENV=production
    

Now if you login as Administrator you will find the new project added.

现在,如果您以管理员身份登录,您会发现添加了新项目。

For more information, refer to the "Import bare repositories into GitLab project instance" under http://{your-gitlab-server}/help/raketasks.

更多信息请参考 下的“将裸仓库导入 GitLab 项目实例” http://{your-gitlab-server}/help/raketasks

In your case, you can login to your old TKL system and rsync all bare repos to the new instance, followed by an import.

在您的情况下,您可以登录到旧的 TKL 系统并将所有裸存储库 rsync 到新实例,然后导入。

回答by tvw

I did it practically the following way after reading ChrisA answer, which gave me a little headache about how to do it practically. The example copies a repo from github to gitlab, to make source and destination a little bit clearer.

在阅读了 ChrisA 的答案后,我几乎按照以下方式进行了操作,这让我对如何实际操作感到有些头疼。该示例将 repo 从 github 复制到 gitlab,以使源和目标更清晰一点。

  1. Clone the old repo from github onto a dev machine (which creates a bare repo):

    $ git clone --mirror [email protected]:me/myrepo.git
    
  2. Create a blank repo on the new gitlab.

  3. Add the new repo as a remote on the dev machine.

    $ cd myrepo.git
    $ git remote add newRepo [email protected]:me/myrepo.git
    
  4. Push everything back to the new repo.

    $ git push --mirror newRepo
    
  1. 将旧仓库从 github 克隆到开发机器上(创建一个裸仓库):

    $ git clone --mirror [email protected]:me/myrepo.git
    
  2. 在新的 gitlab 上创建一个空白的 repo。

  3. 添加新的 repo 作为开发机器上的远程。

    $ cd myrepo.git
    $ git remote add newRepo [email protected]:me/myrepo.git
    
  4. 将所有内容推回到新的回购中。

    $ git push --mirror newRepo
    

That's it.

就是这样。

This way it copied all branches and tags to the new destination.

通过这种方式,它将所有分支和标签复制到新目的地。

You can now remove the cloned bare repo from your dev machine.

您现在可以从开发机器中删除克隆的裸存储库。

回答by keypress

If your Gitlab is >= 8.9, then you can use export/importto migrate repos.

如果您的 Gitlab 是 >= 8.9,那么您可以使用导出/导入来迁移存储库。