如何将大型二进制文件从主模块移动到 git 子模块?
我在名为“videos”的目录中有一堆视频。不幸的是,我将那个大文件夹提交给了 git,导致 git 对于某些活动(例如克隆)变得非常慢。所以我做了一些研究并发现了 git 子模块,但我似乎不太理解它们。
这就是我所做的:
- 我在 ssh://dev.example.org/var/git/project/microsite_videos 上为视频创建了一个单独的存储库,并将视频放在那里。
- 我从 ssh://dev.example.org/var/git/project/microsite 的主存储库中删除了视频并提交了删除。我意识到这不会从历史记录中删除视频,但我想确保在更改历史记录之前我理解子模块。
我将视频作为子模块添加回来:
git 子模块添加 ssh://dev.example.org/var/git/project/microsite_videos 视频
我将这些更改提交给了 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:
- 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.
- 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.
I added the videos back as a submodule:
git submodule add ssh://dev.example.org/var/git/project/microsite_videos videos
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要忘记子模块只是指向特定存储库的特定提交的指针。
请参阅“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.