Git 克隆到另一个现有的 Git 存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10360342/
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
Git Clone Into Another Existing Git Repo
提问by botbot
Am I going to run into any issues if I git clone a repo into an existing git repo?
如果我将仓库克隆到现有的 git 仓库中,我会遇到任何问题吗?
For sake of simplification, I am developing a library "lib/" that should be available to all of my projects. This is a separate git repo. I'd like to import this lib/ into all of my projects, and update it only in one place, never touch it from any of the projects, just use it.
为了简化起见,我正在开发一个库“lib/”,它应该可用于我的所有项目。这是一个单独的 git 仓库。我想将这个 lib/ 导入到我的所有项目中,并且只在一个地方更新它,永远不要从任何项目中触及它,只需使用它。
I am assuming this is ok, just wondered if there is anything I should watch out for. Thanks!
我假设这没问题,只是想知道是否有什么我应该注意的地方。谢谢!
采纳答案by VonC
Just for the record, you can clone a git repo within another one:
Everything under your lib
directory will be ignored by the enclosing Git repo, because said lib directory contains a .git
.
只是为了记录,您可以在另一个中克隆一个 git 存储库:
您lib
目录下的所有内容都将被封闭的 Git 存储库忽略,因为所述 lib 目录包含一个.git
.
So it would work, but the enclosing repo would have no idea:
所以它会起作用,但封闭的回购不知道:
- it needs a
lib
directory from another repo - it needs a specificrevision of that
lib
to build properly, even though it would record the SHA1 of the nestedlib
repo tree. (that is a gitlink, a special entry in the index of the parent repo)
That means cloning the enclosing repo, and you will get an empty "lib/
" folder.
- 它需要
lib
来自另一个仓库的目录 - 它需要对其进行特定修订
lib
才能正确构建,即使它会记录嵌套lib
repo 树的 SHA1 。(这是一个gitlink,父存储库索引中的一个特殊条目)
这意味着克隆封闭存储库,您将获得一个空的“lib/
”文件夹。
Those (repo URL and repo SHA1) are precisely the two informations recorded by the parentrepo (the enclosing one) in order to reference a submodule.
It is made to give you access to a fixedrevision of another repo within your repo, but as explained in "True nature of submodules", that doesn't prevent you to locally modify lib
directly within your parent repo.
(As long as you commit your modifications in lib
first, then go one level up back in your parent repo, and commit there as well)
那些(repo URL 和 repo SHA1)正是父repo(封闭的)为了引用子模块而记录的两个信息。
它旨在让您访问存储库中另一个存储库的固定修订版,但如“子模块的真实性质”中所述,这不会阻止您lib
直接在父存储库中进行本地修改。
(只要您首先提交修改lib
,然后在您的父存储库中上一级,并在那里提交)
The main benefit to any contributor of your main project is that, when they will clone said project, they will know they also need lib
if it is declared as a submodule (as mentioned in "Git Submodule Workflow Advice").
对主项目的任何贡献者的主要好处是,当他们克隆所述项目时,他们将知道lib
如果将其声明为子模块(如“ Git 子模块工作流程建议”中所述),他们将知道他们也需要。
回答by botbot
I'm finding that following this tutorial is helpful for understanding submodules if you don't have much prior experience.
我发现如果您之前没有太多经验,那么遵循本教程有助于理解子模块。
http://help.github.com/submodules/
http://help.github.com/submodules/
https://chrisjean.com/git-submodules-adding-using-removing-and-updating/
https://chrisjean.com/git-submodules-adding-using-removing-and-updating/