此版本的 GitHub Enterprise 已停止服务 2021-09-23. 即使针对重大安全问题,也不会发布补丁。 要获得更好的性能、改进的安全性和新功能,请升级到 GitHub Enterprise 的最新版本。 如需升级方面的帮助,请联系 GitHub Enterprise 支持

为企业配置 Git 大型文件存储

Git Large File Storage (Git LFS) 是 Git 的开源扩展,使您能够像处理其他文本文件一样处理大文件。

关于 Git Large File Storage

Git Large File Storage (Git LFS) 是 Git 的开源扩展,使您能够像处理其他文本文件一样处理大文件。 您可以将 Git Large File Storage 与单一仓库、所有个人或组织仓库或企业中的每一个仓库结合使用。 您需要先为企业启用 Git LFS,然后才能为特定仓库或组织启用 Git LFS。

默认情况下, Git Large File Storage 客户端在托管 Git 仓库的同一服务器上存储大型资产。 当 Git LFS 在 您的 GitHub Enterprise Server 实例 设备上启用时,大型资产将存储在 /data/user/storage 中的数据分区中。

如果在企业或仓库上禁用了 Git LFS,则用户无法将 Git LFS 资产推送到 GitHub Enterprise Server 。

更多信息请参阅“关于 Git Large File Storage”、“大文件版本管理”以及 Git Large File Storage 项目站点

为企业配置 Git Large File Storage

  1. 在 GitHub Enterprise Server 的右上角,单击您的个人资料照片,然后单击 Enterprise settings(Enterprise 设置)GitHub Enterprise Server 上个人资料照片下拉菜单中的"Enterprise settings(企业设置)"

  2. 在企业账户侧边栏中,单击 Policies(政策)企业帐户侧边栏中的 Policies(政策)选项卡

  3. Policies(政策)下,单击 Options(选项)企业帐户设置侧边栏中的 Options(选项)选项卡

  4. 在“Git LFS 访问权限”下,使用下拉菜单,然后单击 Enabled(已启用)Disabled(已禁用)Git LFS access

为各个仓库配置 Git Large File Storage

注意: 每个仓库自动从拥有它的组织或用户继承默认设置。 如果仓库所有者已在其所有仓库上强制执行设置,则您不能覆盖默认设置。

  1. 从 GitHub Enterprise Server 上的管理帐户,点击任何页面右上角的 用于访问站点管理员设置的火箭图标
  2. 在搜索字段中,输入仓库的名称,然后单击 Search(搜索)站点管理员设置搜索字段
  3. 在搜索结果中,单击仓库名称。 站点管理设置搜索选项
  4. 在页面的右上角,单击 Admin(管理员)管理员工具
  5. 在左侧边栏中,单击 Admin(管理员)管理员工具
  6. 在“Git LFS”下,单击 Enable(启用)Disable(禁用)禁用按钮

为用户帐户或组织拥有的每个仓库配置 Git Large File Storage

  1. 从 GitHub Enterprise Server 上的管理帐户,点击任何页面右上角的 用于访问站点管理员设置的火箭图标
  2. 在搜索字段中,输入用户或组织的名称,然后单击 Search(搜索)站点管理员设置搜索字段
  3. 在搜索结果中,单击用户或组织的名称。 站点管理设置搜索选项
  4. 在页面的右上角,单击 Admin(管理员)管理员工具
  5. 在左侧边栏中,单击 Admin(管理员)管理员工具
  6. 在“Git LFS”下,单击 Enable(启用)Disable(禁用)禁用按钮

将 Git Large File Storage 配置为使用第三方服务器

默认情况下, Git Large File Storage 客户端在托管 Git 仓库的同一服务器上存储大型资产。 当 Git LFS 在 您的 GitHub Enterprise Server 实例 设备上启用时,大型资产将存储在 /data/user/storage 中的数据分区中。

如果在企业或仓库上禁用了 Git LFS,则用户无法将 Git LFS 资产推送到 GitHub Enterprise Server 。

  1. 在 您的 GitHub Enterprise Server 实例 上禁用 Git LFS。 更多信息请参阅“为企业配置 Git Large File Storage”。

  2. 创建指向第三方服务器的 Git LFS 配置文件。

    # Show default configuration
    $ git lfs env
    > git-lfs/1.1.0 (GitHub; darwin amd64; go 1.5.1; git 94d356c)
    > git version 2.7.4 (Apple Git-66)
     
    > Endpoint=https://GITHUB-ENTERPRISE-HOST/path/to/repo/info/lfs (auth=basic)
     
    # Create .lfsconfig that points to third party server.
    $ git config -f .lfsconfig remote.origin.lfsurl https://THIRD-PARTY-LFS-SERVER/path/to/repo
    $ git lfs env
    > git-lfs/1.1.0 (GitHub; darwin amd64; go 1.5.1; git 94d356c)
    > git version 2.7.4 (Apple Git-66)
     
    > Endpoint=https://THIRD-PARTY-LFS-SERVER/path/to/repo/info/lfs (auth=none)
     
    # Show the contents of .lfsconfig
    $ cat .lfsconfig
    [remote "origin"]
    lfsurl = https://THIRD-PARTY-LFS-SERVER/path/to/repo
  3. 为使各用户的 Git LFS 配置相同,请向仓库提交自定义 .lfsconfig 文件。

    $ git add .lfsconfig
    $ git commit -m "Adding LFS config file"
  4. 迁移任何现有的 Git LFS 资源。 更多信息请参阅“迁移到不同的 Git Large File Storage 服务器”。

迁移到其他 Git Large File Storage 服务器

迁移到其他 Git Large File Storage 服务器之前,您必须将 Git LFS 配置为使用第三方服务器。 解更多信息请参阅“配置 Git Large File Storage 使用第三方服务器”。

  1. 使用第二个远端配置仓库。

    $ git remote add NEW-REMOTE https://NEW-REMOTE-HOSTNAME/path/to/repo
     
    $ git lfs env
    > git-lfs/1.1.0 (GitHub; darwin amd64; go 1.5.1; git 94d356c)
    > git version 2.7.4 (Apple Git-66)
     
    > Endpoint=https://GITHUB-ENTERPRISE-HOST/path/to/repo/info/lfs (auth=basic)
    > Endpoint (NEW-REMOTE)=https://NEW-REMOTE-HOSTNAME/path/to/repo/info/lfs (auth=none)
  2. 从旧远端提取所有对象。

    $ git lfs fetch origin --all
    > Scanning for all objects ever referenced...
    > ✔ 16 objects found
    > Fetching objects...
    > Git LFS: (16 of 16 files) 48.71 MB / 48.85 MB
  3. 将所有对象推送到新远端。

    $ git lfs push NEW-REMOTE --all
    > Scanning for all objects ever referenced...
    > ✔ 16 objects found
    > Pushing objects...
    > Git LFS: (16 of 16 files) 48.00 MB / 48.85 MB, 879.10 KB skipped

延伸阅读