如何用大文件导入git存储库? [英] How to import git repositories with large files?

查看:313
本文介绍了如何用大文件导入git存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于 GitHub不允许推送大于100MB的文件,因此无法 git clone并将包含大文件的存储库推入到GitHub企业中。推送失败:

  remote:错误:GH001:检测到大文件。你可能想尝试Git Large File Storage  -  https://git-lfs.github.com。 
remote:错误:文件large.zip为145.00 MB;这超过了GitHub Enterprise的文件大小限制100.00 MB

(注意:有一个存储库导入器 a>,但这仅适用于github.com,并且需要公开访问您的存储库)



幸运的是,GitHub 自2015年4月起为存储大于100MB的文件提供支持。那么如何将一个具有这种大文件的当前仓库转换成一个可以推送到GitHub LFS兼容仓库?我发现它利用了 git filter-branch BFG Repo-Cleaner by rt​​yley (我使用的版本 1.12.12 ) :


  1. 先决条件:您需要 git lfs 已安装

  2. 在GitHub Enterprise上创建一个新的存储库。您可以将外部Git存储库导入到这个新的存储库中。 >



$ git clone --mirror git @ oldgithost:repo
$ cd repo.git
#镜像到本地目录




  1. 将历史重写为lfs-跟踪您的大文件:



  $ git filter-branch --tree-filter'git lfs track*。{zip,jar}' -  --all 
#writes lsf-追踪到.gitattributes的模式




  1. 使用BFG将相关文件提取到Git LFS中


$ b

  $ java -jar〜/ usr / bfg-repo-cleaner / bfg-1.12.12.jar --convert-to-git-lfs'* .zip'
$ java -jar〜/ usr / bfg-repo --cleanner / bfg-1.12.12.jar --convert-to- git-lfs'* .jar'
#转换大文件(我无法找到多个模式的单线程)




  1. 推送至您的GitHub企业远程设备: class =lang-bash prettyprint-override> $ git push --mirror https://hostname/ghuser/repo.git
    #将镜像推送到新的GitHub Enterprise存储库




    1. 删除临时目录:



      $ cd .. 
    $ rm -rf repo.git






    注意



    由于高I / O,它是建议使用-d选项将历史记录重写到磁盘外的临时目录中,例如在tmpfs上。


    Given that GitHub doesn't allow to push files larger than 100 MB, it is not possible to git clone and push a repository with large files into GitHub enterprise. The push fails with a:

    remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
    remote: error: File large.zip is 145.00 MB; this exceeds GitHub Enterprise's file size limit of 100.00 MB
    

    (N.B.: there is a repository importer, but this is only for github.com, and requires public access to your repository)

    Fortunately, GitHub provides support for storage of files larger than 100MB since April 2015. So how to convert a current repository with such large files into a GitHub LFS compatible repository I can push to?

    解决方案

    The easiest way I found was taking advantage of git filter-branch and the BFG Repo-Cleaner by rtyley (I used version 1.12.12):

    1. Prerequisite: you need to have git lfs installed

    2. Create a new repository on GitHub Enterprise. You'll import your external Git repository to this new repository.

    3. Clone the repository you want to migrate to a local folder:

    $ git clone --mirror git@oldgithost:repo
    $ cd repo.git
    # mirror into a local directory
    

    1. Rewrite the history to lfs-track your large files1:

    $ git filter-branch --tree-filter 'git lfs track "*.{zip,jar}"' -- --all
    # writes the patterns to lsf-track into .gitattributes
    

    1. Use the BFG to extract the relevant files into Git LFS

    $ java -jar ~/usr/bfg-repo-cleaner/bfg-1.12.12.jar --convert-to-git-lfs '*.zip'
    $ java -jar ~/usr/bfg-repo-cleaner/bfg-1.12.12.jar --convert-to-git-lfs '*.jar'
    # Convert large files (I couldn't find a one-liner for multiple patterns)
    

    1. Push to your GitHub enterprise remote:

    $ git push --mirror https://hostname/ghuser/repo.git
    # Pushes the mirror to the new GitHub Enterprise repository
    

    1. Delete temporary dir:

    $ cd ..
    $ rm -rf repo.git
    


    Notes

    1 Due to the high I/O, it is recommended to rewrite the history into a temporary directory off-disk with the -d option, e.g. on tmpfs.

    这篇关于如何用大文件导入git存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆