如何设置 git 项目以使用外部存储库子模块?
我想创建一个拉入远程存储库的存储库。
例如,假设 jQuery 作为子模块:
git://github.com/jquery/jquery.git
使用 jQuery 作为子模块创建存储库并将我自己的外部添加为远程存储库的过程是什么。
另外,一旦设置完毕,如果我推/拉到我自己的遥控器,外部设备会保持不变吗?
I'd like to create a repo which pulls in a remote repo.
For example, let's say jQuery as a submodule:
git://github.com/jquery/jquery.git
What would be the process of creating a repo with jQuery as a submodule and adding my own external as a remote repo.
Also once this is setup, if I push / pull to my own remote, will the external remain intact?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
子模块确实非常容易引用和使用。假设您已经将 MyWebApp 设置为存储库,请从终端发出以下命令:
这将创建一个名为
externals/jquery
* 的目录,并将其链接到 github jquery 存储库。现在我们只需要初始化子模块并将代码克隆到其中:您现在应该将所有最新代码克隆到子模块中。如果 jquery 存储库发生更改并且您想要下载最新的代码,只需再次发出
submodule update
命令即可。请注意:我的项目中通常有许多外部存储库,因此我总是将存储库分组在“externals”目录下。在线 Pro Git Book 提供了一些关于子模块(以及一般的 git)的好信息以易于阅读的方式。另外,
git help submodule
也会提供很好的信息。或者查看 git wiki 上的 Git 子模块教程。我注意到这篇博客文章讨论了子模块并将它们与 Subversion 的 svn:externals 机制进行了比较: http ://speirs.org/blog/2009/5/11/understanding-git-submodules.html
* 作为最佳实践,您应该始终将子模块放在它们自己的目录中,例如Externals。如果不这样做,您的根项目目录很快就会变得非常混乱。
Submodules are really, really easy to reference and use. Assuming you already have MyWebApp set up as a repo, from terminal issue these commands:
This will create a directory named
externals/jquery
* and link it to the github jquery repository. Now we just need to init the submodule and clone the code to it:You should now have all the latest code cloned into the submodule. If the jquery repo changes and you want to pull the latest code down, just issue the
submodule update
command again. Please note: I typically have a number of external repositories in my projects, so I always group the repos under an "externals" directory.The online Pro Git Book has some good information on submodules (and git in general) presented in an easy-to-read fashion. Alternately,
git help submodule
will also give good information. Or take a look at the Git Submodule Tutorial on the git wiki.I noticed this blog entry which talks about submodules and compares them to Subversion's svn:externals mechanism: http://speirs.org/blog/2009/5/11/understanding-git-submodules.html
* As a best practice, you should always place your submodules in their own directory, such as Externals. If you don't, your root project directory can become very cluttered very fast.
您需要了解的大部分内容已经得到解答,因此我不会费心解决这个问题,但是,我发现了一小部分通常会丢失的信息。
如您所知,“git pull”不会更新子模块,“git submodules update”也不会下载这些子模块的最新 HEAD。
要将所有子模块更新到最新的上游版本,您可以使用
如果您经常更改子模块,并且有很多子模块,那么“git foreach”将变得非常有用。
Most of what you need to know has already been answered, so I won't bother addressing that, however, I've found a small piece of information that's usually missing.
As you know, "git pull" won't update the submodules, and "git submodules update" won't download the latest HEAD of those submodules either.
To update all of your submodules to their latest upstream revision, you can use
If you often alter your submodules, and have lots of the, then "git foreach" will become invaluable.
我认为@Hugo 的答案可能就是您所需要的并且工作正常。所以我找到了一种更简单的方法。
就这样。
所以一个完整的工作流程可能是:
I think that the @Hugo answer could be what you need and works fine. So I have found a easier way.
That's all.
So a complete workflow could be: