如何将大型二进制文件从主模块移动到 git 子模块?

发布于 2024-12-18 12:49:09 字数 843 浏览 1 评论 0原文

我在名为“videos”的目录中有一堆视频。不幸的是,我将那个大文件夹提交给了 git,导致 git 对于某些活动(例如克隆)变得非常慢。所以我做了一些研究并发现了 git 子模块,但我似乎不太理解它们。

这就是我所做的:

  1. 我在 ssh://dev.example.org/var/git/project/microsite_videos 上为视频创建了一个单独的存储库,并将视频放在那里。
  2. 我从 ssh://dev.example.org/var/git/project/microsite 的主存储库中删除了视频并提交了删除。我意识到这不会从历史记录中删除视频,但我想确保在更改历史记录之前我理解子模块。
  3. 我将视频作为子模块添加回来:

    git 子模块添加 ssh://dev.example.org/var/git/project/microsite_videos 视频
    
  4. 我将这些更改提交给了 master。

这是我的 .gitmodules 文件:

[submodule "videos"]
    path = videos
    url = ssh://dev.example.org/var/git/project/microsite_videos

起初它似乎工作正常,但我对它的一些行为感到困惑。特别是,刚才我将 master 合并到分支中,视频文件夹就消失了。 .gitmodules 文件仍然存在,但任何拉取或更新视频文件夹的尝试只会给我一个新的提示,而不会执行任何操作。

我做错了什么,如何提高对子模块的理解,这样我就不必每次尝试分支和合并时都陷入困境?

I have a bunch of videos inside a directory named "videos". I committed that unfortunately large folder to git, causing git to become very slow for some activities such as cloning. So I did some research and discovered git submodules, but I don't seem to understand them very well.

Here's what I did:

  1. I created a separate repository just for the videos at ssh://dev.example.org/var/git/project/microsite_videos and put the videos in there.
  2. I deleted the videos from my main repo at ssh://dev.example.org/var/git/project/microsite and committed the delete. I realize this doesn't remove the videos from history, but I wanted to make sure I understood submodules before I change history.
  3. I added the videos back as a submodule:

    git submodule add ssh://dev.example.org/var/git/project/microsite_videos videos
    
  4. I committed these changes to master.

Here is my .gitmodules file:

[submodule "videos"]
    path = videos
    url = ssh://dev.example.org/var/git/project/microsite_videos

At first it seemed to work OK, but I'm confused about some of its behavior. In particular, just now I merged master into a branch and the videos folder just disappeared. The .gitmodules file is still there, but any attempt to pull or update the videos folder just gives me a new prompt without appearing to do anything.

What am I doing wrong, and how can I improve the my understanding of submodules so I don't have to flounder every time I try to branch and merge?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝戈者 2024-12-25 12:49:09

不要忘记子模块只是指向特定存储库的特定提交的指针。
请参阅“Git 子模块:指定分支/标签”。

这意味着,合并后,您仍然拥有指针(在 .gitmodules 中并作为树中的特殊条目),但您需要 git submodule update 才能刷新子模块内容。
如果更新失败,请参阅“Git 子模块头”。

Don't forget that submodules are just a pointer to a specific commit of a specific repo.
See "Git submodules: Specify a branch/tag".

Meaning that, after your merge, you still have your pointer (in .gitmodules and as a special entry in the tree), but you need a git submodule update in order to refresh the submodule content.
See "Git submodule head" if that update should fail.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文