在 GitHub 上使用别人的 repo 作为 Git 子模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5252450/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:10:35  来源:igfitidea点击:

Using someone else's repo as a Git Submodule on GitHub

gitversion-controlrepositorygithubgit-submodules

提问by Graham Conzett

I am trying to find out if it is possible to use someone else's repository (or branch of a repository) as a Submodule in your own Git repository. Documentation on github itself is either missing, or I'm not using the right terminology to look for it. If this isn't the preferred way to go about including a public repository as a shared library within ones git project, suggestions as an alternative best practice would be appreciated.

我试图找出是否可以将其他人的存储库(或存储库的分支)用作您自己的 Git 存储库中的子模块。github 本身的文档要么丢失,要么我没有使用正确的术语来查找它。如果这不是将公共存储库作为共享库包含在一个 git 项目中的首选方式,建议作为替代最佳实践将不胜感激。

回答by Mark Longair

Yes, you can add any repository as a submodule in your project. Just do:

是的,您可以将任何存储库添加为项目中的子模块。做就是了:

git submodule add git://github.com/whomsoever/whatever.git

... in the top level of your repository. This is indeed the easiest way with git to use some existing useful repository within your own. For more information on submodules, you could look at:

...在您的存储库的顶层。这确实是使用 git 使用您自己的现有有用存储库的最简单方法。有关子模块的更多信息,您可以查看:

Update:as jfountainpoints out below, if you want to add the submodule at a subdirectory path (or with a name different from the default) you can supply that as an additional parameter to that command, e.g.:

更新:正如jfountain在下面指出的那样,如果您想在子目录路径(或与默认名称不同的名称)中添加子模块,您可以将其作为该命令的附加参数提供,例如:

git submodule add git://github.com/whomsoever/whatever.git foo/bar