Git子模块没有额外的重量 [英] Git submodule without extra weight
问题描述
我还不是Git的主人,面临着一个问题,我无法弄清楚如何解决。我有一个使用WordPress定制框架的回购站,并且通过 git submodule add wp_repo_url
从原始回购站添加了WordPress作为子模块。当我将我的repo克隆到本地机器时:
git clone --recursive https://github.com/user/repo local_dir
按预期下载WP子模块,但问题在于 - 实际文件只有20.7Mb,和 .git / modules / core / objects / pack
我有一个巨大的124Mb .pack文件,我认为这个文件很像提交历史记录/修订版子模块。
如何在克隆时重新添加子模块或进行修改以防止下载此额外重量? 更新:
在@iclmam的帮助下,我想出了以下设置:
- 我的骨架回购将使用WordPress作为子模块,当从骨架创建新项目时,包含历史记录的整个原始回购
- 克隆它没有 - 递归选项只获取子模块的主文件和空文件夹
- IF 我需要WordPress机智h完整的历史记录 - 例如,如果我需要在不同的WP分支/标签之间切换以测试我的插件/主题向后兼容性 - 那么我将获得具有完整历史记录的此子模块
-
如果我只是需要一个简单的干净安装最近的WP版本,我会换成wp目录,并以旧的方式:
curl -L -O http://wordpress.org/latest.zip
unzip latest.zip
mv wordpress / *。
rm latest.zip
rm -rf wordpress
不是一个完美的解决方案(我想尽可能自动化所有东西),但它现在可以使用。
对原始问题的任何建议感谢。
自Git 2.10+(2016年第3季度)以来,您将能够定期进行克隆......并且仍然可以从子模块的浅克隆
获益。您只需将该配置记录到 .gitmodules
:
git config -f .gitmodules submodule。< name> .shallow true
添加,提交和推送:克隆您的repo的任何人(常规克隆,完整历史记录)将只获得深度为1为子模块< name>
。
请参阅 commit f6fb30a , commit abed000 and commit 37f52e9 (2016年8月3日)作者: Stefan Beller( stefanbeller
) 。
(由 Junio C Hamano - gitster
- 在提交dc7e09a ,08 2016年8月)
> 子模块更新
:learn - [no - ] recommended-shallow
选项
有时,子模块的历史不会被上游项目视为重要。为了使下游用户更容易,在
.gitmodules
子模块。< name> .shallow ' >,它可以用来推荐上游是否认为历史是重要的。
默认情况下,该字段在初始克隆中得到遵守,可以通过给出
- no-recommend-shallow
选项。
I'm not a Git master yet, faced a problem I can't figure out how to fix. I have a repo with my WordPress custom skeleton and I've added WordPress as a submodule from its original repo by git submodule add wp_repo_url
. When I clone my repo to local machine with:
git clone --recursive https://github.com/user/repo local_dir
it downloads the WP submodule as expected, but here's the problem - actual files are only 20.7Mb, and in .git/modules/core/objects/pack
I've got a huge 124Mb .pack file, which, I suppose, is smth like commit history / revisions of that submodule.
How can I re-add submodule or modify while cloning to prevent downloading this extra weight?
UPDATE:
With the help of @iclmam I've came up with the following setup:
- my skeleton repo will have WordPress as a submodule, the whole original repo with history
- when creating a new project from skeleton, I'll clone it without --recursive option to get only the main files and empty folder for submodule
- IF I need WordPress with full history - for example, if I need to switch between different WP branches/tags to test my plugin/theme backward compatibility - then I'll get this submodule with full history
if I just need a plain clean install of recent WP version, I'll change into wp directory and go the old way:
curl -L -O http://wordpress.org/latest.zip unzip latest.zip mv wordpress/* . rm latest.zip rm -rf wordpress
Not a perfect solution (I wanted to automate everything as much as possible), but it works for now.
Any advices on the original question are appreciated.
since Git 2.10+ (Q3 2016), you will be able to do a regular clone... and still benefit from shallow clone for submodules.
All you need to do is record that configuration in your .gitmodules
:
git config -f .gitmodules submodule.<name>.shallow true
Add, commit, and push: anyone cloning your repo (regular clone, full history) will get only a depth of 1 for the submodule <name>
.
See commit f6fb30a, commit abed000 and commit 37f52e9 (03 Aug 2016) by Stefan Beller (stefanbeller
).
(Merged by Junio C Hamano -- gitster
-- in commit dc7e09a, 08 Aug 2016)
> submodule update
: learn --[no-]recommend-shallow
option
Sometimes the history of a submodule is not considered important by the projects upstream. To make it easier for downstream users, allow a boolean field '
submodule.<name>.shallow
' in.gitmodules
, which can be used to recommend whether upstream considers the history important.This field is honored in the initial clone by default, it can be ignored by giving the
--no-recommend-shallow
option.
这篇关于Git子模块没有额外的重量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!