主控上的Git子模块 [英] Git submodules on master

查看:125
本文介绍了主控上的Git子模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有没有什么办法可以让超级项目的子模块始终引用这个子模块的头部?主分支,所以在超级项目中的git submodule update或git pull只是对所有子模块执行git pull。

谢谢。

解决方案

简短的答案是否定的。我们的想法是,您确切知道子模块的特定提交可以与您的项目一起工作,并且您不希望通过获取即时更新来实现任何未定义或意外的行为。子模块直接由两件事情来表示:gitmodules中的条目和gitlink,它是子模块所需提交的SHA1的引用。 SHA1,而不是refname。



你问的是真正的超级项目有什么不知道子模块的内容。考虑一下:项目的不同克隆可能会在不同的时间更新子模块,最终会有不同版本的子模块,然后如果在项目中进行了提交,他们必须在子模块中记录不同的提交。当你合并时,你可能不得不忽略他们所说的并且再次拉动。结果是,你的请求正在避免子模块的整个想法:要知道你有什么。如果你说你正在使用主人,你会从现在开始两个月回来,不知道这意味着什么!



如果你想永远得到目前的主分支,你最好自己做。编写一个脚本来引入所有子模块,并立即运行它,提交更新的版本。 (尽管测试第一,但!)这里的重点是,对于子模块,对于每个超级项目提交,您必须确切知道您使用的子项目的版本。您可以选择多久更新一次子模块的版本;它可以是每天,如果你喜欢。



另一种方法是将子模块的目录添加到你的gitignore,并写一个快速的小脚本更新它们(也可能是克隆它们)。这会让你有能力知道过去某个时间点的版本。


I am new to git submodules, and I notice they always refer to specific commits.

Is there any way for a superproject's submodules to always refer to the head of the master branch, so "git submodule update" or "git pull" in the superproject simply does "git pull" on all submodules.

Thanks.

解决方案

The short answer is no. The idea is that you know for sure a specific commit of the submodule will work with your project, and you don't want any undefined or unexpected behavior coming in by getting on-the-fly updates. A submodule is directly represented by two things: an entry in .gitmodules, and a gitlink, which is a reference to the SHA1 of the desired commit of the submodule. SHA1, not refname.

What you're asking is really for the superproject to have no idea what's in the submodule. Think about it: different clones of your project could have updated the submodule at different times, and end up with different versions of it there, and then if commits were made in your project, they'd have to record different commits in the submodule. When you merged, you'd have to just ignore what they both say and pull again, probably. The upshot is that your request is avoiding the entire idea of submodules: to know what you have. If you say you're using "master", you'd come back two months from now and have no idea what that meant!

If you want to always get the current master branch, you're better off doing it yourself. Write a script to pull in all the submodules, and run it now and then, committing the updated versions. (Test first, though!) The point here is that with submodules, for every superproject commit, you must know exactly what version of the subproject you're using. It's your choice how often you want to update the version of the submodule; it can be daily if you like.

The alternative would be to add the directory(ies) for the submodule(s) to your gitignore, and write a quick little script to update them (and probably one to clone them too). This would cost you the ability to know what version you had at some point in the past.

这篇关于主控上的Git子模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆