简体   繁体   English

Git 克隆到另一个现有的 Git 存储库

[英]Git Clone Into Another Existing Git Repo

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.为了简化起见,我正在开发一个库“lib/”,它应该可用于我的所有项目。 This is a separate git repo.这是一个单独的 git 仓库。 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/ 导入到我的所有项目中,并且只在一个地方更新它,永远不要从任何项目中触及它,只需使用它。

I am assuming this is ok, just wondered if there is anything I should watch out for.我假设这没问题,只是想知道是否有什么我应该注意的地方。 Thanks!谢谢!

Just for the record, you can clone a git repo within another one:只是为了记录,您可以在另一个中克隆一个 git repo:
Everything under your lib directory will be ignored by the enclosing Git repo, because said lib directory contains a .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它需要来自另一个 repo 的lib目录
  • it needs a specific revision of that lib to build properly, even though it would record the SHA1 of the nested lib repo tree.它需要对该lib进行特定修订才能正确构建,即使它会记录嵌套lib库树的 SHA1。 (that is a gitlink , a special entry in the index of the parent repo) (这是一个gitlink ,父仓库索引中的一个特殊条目)
    That means cloning the enclosing repo, and you will get an empty " lib/ " folder.这意味着克隆封闭的存储库,您将获得一个空的“ lib/ ”文件夹。

Those (repo URL and repo SHA1) are precisely the two informations recorded by the parent repo (the enclosing one) in order to reference a submodule .那些(repo URL 和 repo SHA1)正是repo(封闭的)为了引用子模块而记录的两个信息。
It is made to give you access to a fixed revision 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.它旨在让您访问存储库中另一个存储库的固定修订版,但如“子模块的真实性质”中所述,这不会阻止您直接在父存储lib本地修改lib
(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) (只要你先在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 子模块工作流建议”中所述),他们将知道他们还需要lib

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/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM