【问题标题】:Fork a specific dir from a huge repository从一个巨大的存储库中分叉一个特定的目录
【发布时间】:2019-08-31 22:14:33
【问题描述】:

我想 fork 一个巨大的存储库 (10GB),将其过滤到特定目录并将过滤后的版本推送到新的 Github 存储库。

我已经使用these 指令来拉取和过滤到我的目录,这很有效。但是当我尝试将过滤后的 repo 推送回 Github 时,我收到了这个错误:

$ git push origin master --force
Enumerating objects: 2292154, done.
Counting objects: 100% (2292154/2292154), done.
Delta compression using up to 8 threads
Compressing objects: 100% (562030/562030), done.
error: RPC failed; curl 55 SSL_write() returned SYSCALL, errno = 32
fatal: the remote end hung up unexpectedly
Writing objects: 100% (2292154/2292154), 7.03 GiB | 40.92 MiB/s, done.
Total 2292154 (delta 1726549), reused 2292154 (delta 1726549)
fatal: the remote end hung up unexpectedly
Everything up-to-date

我尝试了here提出的解决方案,但错误仍然存​​在。

有没有办法 fork 一个特定的目录并减少总 repo 大小以使其更易于管理?

【问题讨论】:

    标签: git github


    【解决方案1】:

    鉴于您提供的链接,问题可能与提交的大小有关。也许将你的 repo 过滤到这个目录,但保持与它相关的提交会有所帮助。

    来自git filter-branch 手册:

    重写存储库,使其看起来好像 foodir/ 是它的项目根,并丢弃所有其他历史记录:

    git filter-branch --subdirectory-filter foodir -- --all

    希望对你有帮助。

    要仅保留此目录(并将其保留在结构中),它会稍微复杂一些。

    git-filter-branch 手册中判断示例,应该可以解决问题:

    git filter-branch --index-filter \
       'git ls-files -s foodir/ |
           GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
           git update-index --index-info &&
           mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"
       ' -- --all
    

    简而言之:git ls-files -s foodir/ 的输出仅显示 foodir/ 中文件的索引内容(blobtree 和文件名);这个文件列表被放回索引中。

    无论如何,正如我在评论中指出的那样,您将无法简单地合并它 - 因为提交现在不同了。

    【讨论】:

    • 谢谢!这行得通。有没有办法在将我的目录保持在当前位置(而不是根目录)的同时做到这一点?这将使以后更容易合并回上游。
    • 你可以试试git filter-branch --index-filter。对不起,简短,当我有更多时间时,我会详细说明。请注意, git filter-branch 会重写历史记录,您将无法简单地将其合并到原始存储库中。
    猜你喜欢
    • 2020-12-30
    • 2015-03-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-29
    • 2013-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多