将Git克隆到另一个现有的Git回购中 [英] Git Clone Into Another Existing Git Repo

查看:68
本文介绍了将Git克隆到另一个现有的Git回购中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将某个存储库克隆到现有的git存储库中,我会遇到任何问题吗?

Am I going to run into any issues if I git clone a repo into an existing git repo?

为简化起见,我正在开发一个库"lib/",该库应可用于我的所有项目.这是一个单独的git repo.我想将此lib/导入到我的所有项目中,并仅在一个地方进行更新,切勿在任何项目中使用它,而只需使用它即可.

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.

我认为这是可以的,只是想知道是否有什么我应该注意的.谢谢!

I am assuming this is ok, just wondered if there is anything I should watch out for. Thanks!

推荐答案

仅作记录,您可以在另一个仓库中克隆一个git repo:
封闭的Git存储库将忽略lib目录下的所有内容,因为所说的lib目录包含.git.

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.

这样就可以了,但是随附的回购协议却毫无头绪:

So it would work, but the enclosing repo would have no idea:

  • 它需要另一个仓库中的lib目录
  • 它需要对该lib进行特定的修订才能正确构建,即使它会记录嵌套的lib回购树的SHA1. (这是 gitlink ,是父存储库索引中的特殊条目)
    这意味着克隆封闭的存储库,您将获得一个空的"lib/"文件夹.
  • it needs a lib directory from another repo
  • it needs a specific revision of that lib to build properly, even though it would record the SHA1 of the nested lib 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.

这些(存储库URL和存储库SHA1)正是存储库(包含该存储库)记录的两个信息,以便引用 lib您的父仓库.
(只要您首先在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.
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.
(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").

这篇关于将Git克隆到另一个现有的Git回购中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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