是否可以有浅子模块?我有一个包含几个子模块的 super 项目,每个子模块都有很长的历史,所以它不必要地拖着所有的历史。
我找到的只有 this unanswered thread .
我应该只是hack git-submodule实现这个?
最佳答案
即将推出的 git1.8.4 (July 2013) 中的新功能:
"
git submodule update" can optionally clone the submodule repositories shallowly.
git config -f .gitmodules submodule.<name>.shallow true 记录。Add the
--depthoption to the add and update commands of "git submodule", which is then passed on to the clone command. This is useful when the submodule(s) are huge and you're not really interested in anything but the latest commit.
Tests are added and some indention adjustments were made to conform to the rest of the testfile on "submodule update can handle symbolic links in pwd".
Signed-off-by: Fredrik Gustafsson
<iveqy@iveqy.com>
Acked-by: Jens Lehmann<Jens.Lehmann@web.de>
# add shallow submodule
git submodule add --depth 1 <repo-url> <path>
git config -f .gitmodules submodule.<path>.shallow true
# later unshallow
git config -f .gitmodules submodule.<path>.shallow false
git submodule update <path>
命令可以按任何顺序运行。 git submodule 命令执行实际的克隆(这次使用深度 1)。 git config 命令使该选项对于稍后将递归克隆 repo 的其他人永久存在。https://github.com/foo/bar 并且您想在您的 repo https://github.com/lorem/ipsum 中添加 path/to/submodule 作为子模块。命令可能如下所示:git submodule add --depth 1 git@github.com:lorem/ipsum.git path/to/submodule
git config -f .gitmodules submodule.path/to/submodule.shallow true
以下结果也相同(相反的顺序):git config -f .gitmodules submodule.path/to/submodule.shallow true
git submodule add --depth 1 git@github.com:lorem/ipsum.git path/to/submodule
下次有人运行 git clone --recursive git@github.com:foo/bar.git 时,它会 pull 入 https://github.com/foo/bar 的整个历史记录,但它只会按预期浅克隆子模块。--depth
This option is valid for
addandupdatecommands.
Create a 'shallow' clone with a history truncated to the specified number of revisions.
As far as I can tell this option isn't usable for submodules which don't track
mastervery closely. If you set depth 1, thensubmodule updatecan only ever succeed if the submodule commit you want is the latest master. Otherwise you get "fatal: reference is not a tree".
submodule update --depth 还有一次成功的机会,即使 SHA1 可以从远程仓库 HEAD 之一直接访问。stefanbeller )(2016 年 2 月 24 日)。gitster ) 。gitster -- 在 commit 9671a76 中 merge ,2016 年 2 月 26 日)submodule: try harder to fetch needed sha1 by direct fetching sha1
When reviewing a change that also updates a submodule in Gerrit, a common review practice is to download and cherry-pick the patch locally to test it.
However when testing it locally, the 'git submodule update' may fail fetching the correct submodule sha1 as the corresponding commit in the submodule is not yet part of the project history, but also just a proposed change.
If
$sha1was not part of the default fetch, we try to fetch the$sha1directly. Some servers however do not support direct fetch by sha1, which leadsgit-fetchto fail quickly.
We can fail ourselves here as the still missing sha1 would lead to a failure later in the checkout stage anyway, so failing here is as good as we can get.
It would seem to me that commit fb43e31 requests the missing commit by SHA1 id, so the
uploadpack.allowReachableSHA1InWantanduploadpack.allowTipSHA1InWantsettings on the server will probably affect whether this works.
I wrote a post to the git list today, pointing out how the use of shallow submodules could be made to work better for some scenarios, namely if the commit is also a tag.
Let's wait and see.
I guess this is a reason why fb43e31 made the fetch for a specific SHA1 a fallback after the fetch for the default branch.
Nevertheless, in case of “--depth 1” I think it would make sense to abort early: if none of the listed refs matches the requested one, and asking by SHA1 isn't supported by the server, then there is no point in fetching anything, since we won't be able to satisfy the submodule requirement either way.
git config -f .gitmodules submodule.<name>.shallow true
有关更多信息,请参阅“Git submodule without extra weight ”。sschuberth )(2017 年 4 月 19 日)。sschuberth -- 在 commit 8d3047c 中 merge ,2017 年 4 月 20 日)a clone of this submodule will be performed as a shallow clone (with a history depth of 1)
shallow = trueon.gitmodulesonly affects the reference tracked by the HEAD of the remote when using--recurse-submodules, even if the target commit is pointed to by a branch, and even if you putbranch = mybranchon the.gitmodulesas well.
HEAD:.gitmodules 文件时,子模块支持已更新为从 .gitmodules 处的 blob 读取。ao2 ) 在 Junio C Hamano -- gitster -- 中 merge ,2018 年 11 月 13 日)
submodule: support reading.gitmoduleswhen it's not in the working tree
When the
.gitmodulesfile is not available in the working tree, try using the content from the index and from the current branch.
This covers the case when the file is part of the repository but for some reason it is not checked out, for example because of a sparse checkout.
This makes it possible to use at least the '
git submodule' commands which read thegitmodulesconfiguration file without fully populating the working tree.
Writing to
.gitmoduleswill still require that the file is checked out, so check for that before callingconfig_set_in_gitmodules_file_gently.
Add a similar check also in
git-submodule.sh::cmd_add()to anticipate the eventual failure of the "git submodule add" command when.gitmodulesis not safely writeable; this prevents the command from leaving the repository in a spurious state (e.g. the submodule repository was cloned but.gitmoduleswas not updated becauseconfig_set_in_gitmodules_file_gentlyfailed).
Moreover, since
config_from_gitmodules()now accesses the global object store, it is necessary to protect all code paths which call the function against concurrent access to the global object store.
Currently this only happens inbuiltin/grep.c::grep_submodules(), so callgrep_read_lock()before invoking code involvingconfig_from_gitmodules().
NOTE: there is one rare case where this new feature does not work properly yet: nested submodules without
.gitmodulesin their working tree.
auselen ) 在 Junio C Hamano -- gitster -- 中 merge ,2019 年 10 月 9 日)git submodule update 文档。phil-blain ) 在 Junio C Hamano -- gitster -- 中 merge ,2019 年 12 月 5 日)
doc: mention that 'git submodule update' fetches missing commitsHelped-by: Junio C Hamano
Helped-by: Johannes Schindelin
Signed-off-by: Philippe Blain
'
git submoduleupdate' will fetch new commits from the submodule remote if the SHA-1 recorded in the superproject is not found. This was not mentioned in the documentation.
git clone --recurse-submodules”和备用对象存储之间的交互设计不当。The documentation and code have been taught to make more clear recommendations when the users see failures.
jhowtan ) 在 Junio C Hamano -- gitster -- 中 merge ,2019 年 12 月 10 日)
submodule--helper: advise on fatal alternate errorSigned-off-by: Jonathan Tan
Acked-by: Jeff King
When recursively cloning a superproject with some shallow modules defined in its
.gitmodules, then recloning with "--reference=<path>", an error occurs. For example:
git clone --recurse-submodules --branch=master -j8 \
https://android.googlesource.com/platform/superproject \
master
git clone --recurse-submodules --branch=master -j8 \
https://android.googlesource.com/platform/superproject \
--reference master master2
fails with:
fatal: submodule '<snip>' cannot add alternate: reference repository
'<snip>' is shallow
When a alternate computed from the superproject's alternate cannot be added, whether in this case or another, advise about configuring the "
submodule.alternateErrorStrategy" configuration option and using "--reference-if-able" instead of "--reference" when cloning.
Doc: explain submodule.alternateErrorStrategySigned-off-by: Jonathan Tan
Acked-by: Jeff King
Commit 31224cbdc7 ("
clone: recursive and reference option triggers submodule alternates", 2016-08-17, Git v2.11.0-rc0 -- merge listed in batch #1) taught Git to support the configuration options "submodule.alternateLocation" and "submodule.alternateErrorStrategy" on a superproject.
If "
submodule.alternateLocation" is configured to "superproject" on a superproject, whenever a submodule of that superproject is cloned, it instead computes the analogous alternate path for that submodule from$GIT_DIR/objects/info/alternatesof the superproject, and references it.
The "
submodule.alternateErrorStrategy" option determines what happens if that alternate cannot be referenced.
However, it is not clear that the clone proceeds as if no alternate was specified when that option is not set to "die" (as can be seen in the tests in 31224cbdc7).
Therefore, document it accordingly.
submodule.alternateErrorStrategy::
Specifies how to treat errors with the alternates for a submodule as computed via
submodule.alternateLocation.
Possible values areignore,info,die.
Default isdie.
Note that if set toignoreorinfo, and if there is an error with the computed alternate, the clone proceeds as if no alternate was specified.
git submodule update --quiet ) 没有将安静选项向下传播到底层 man ( git fetch ),这已在 Git 2.32(2021 年第二季度)中得到纠正。nwc10 ) merge 于 Junio C Hamano -- gitster -- ,2021 年 5 月 11 日)
submodule update: silence underlying fetch with "--quiet"Signed-off-by: Nicholas Clark
Commands such as
$ git submodule update --quiet --init --depth=1involving shallow clones, call the shell function
fetch_in_submodule,which in turn invokesgit fetch.
Pass the--quietoption onward there.
关于git - 如何制作浅的 git 子模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2144406/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚
Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack
在选择我想要运行操作的频率时,唯一的选项是“每天”、“每小时”和“每10分钟”。谢谢!我想为我的Rails3.1应用程序运行调度程序。 最佳答案 这不是一个优雅的解决方案,但您可以安排它每天运行,并在实际开始工作之前检查日期是否为当月的第一天。 关于ruby-如何每月在Heroku运行一次Scheduler插件?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/8692687/
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为
我有一大串格式化数据(例如JSON),我想使用Psychinruby同时保留格式转储到YAML。基本上,我希望JSON使用literalstyle出现在YAML中:---json:|{"page":1,"results":["item","another"],"total_pages":0}但是,当我使用YAML.dump时,它不使用文字样式。我得到这样的东西:---json:!"{\n\"page\":1,\n\"results\":[\n\"item\",\"another\"\n],\n\"total_pages\":0\n}\n"我如何告诉Psych以想要的样式转储标量?解