如何在现有仓库中创建子模块 [英] How to create submodule in existing repo

查看:83
本文介绍了如何在现有仓库中创建子模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是git&的新手.对于新项目,我具有以下文件夹结构,所以我要做的是去了Visual Studio,并制作了一个具有此文件夹结构的空项目:

I'm beginner to git & I have the following folder structure for new project, so what I did is I went to visual studio and I made empty project it has this folder structure:

project: (Repo) 
folder1 (sub1)
folder2 (sub2)

我在本地使用git.
我使用sourcetree为项目创建了一个仓库,
现在我无法添加任何子模块,我也不知道为什么.

I'm using git locally.
I created a repo for project using sourcetree,
now I cannot add any submodule, I don't know why.

每当我尝试在Powershell中:

In powershell whenever I try:

PS E:\Projects\Project> git submodule add ./sub1

我遇到以下错误:

sub1 already exists in the index

然后删除sub1 git rm -r sub1 ,然后我再次重复 git子模块add ,我得到了这个新错误:

then removed sub1 git rm -r sub1, then I repeated git submodule add again, and I got this new error:

sub1 already exists and is not a valid git repo

那我做错了吗?

推荐答案

添加子模块表示将另一个git repo克隆到现有的git repo中并保留对其的引用.

Adding a submodule means cloning another git repo inside an existing one and keep a reference to it.

在您的情况下,您没有指定要添加的仓库:

In your case, you did not specify which repo you want to add:

git submodule add -- /url/of/sub1/repo sub1


如果 sub1 sub2 不应被认为是它们自己的git repos,而是主repo文件夹的简单子文件夹,那么您就不需要 git submodule add 命令.
只需在 sub1 sub2 中添加文件,您就可以 git add git commit .
不涉及任何子模块.


if sub1 or sub2 are not supposed to be git repos of their own, but simple sub-folder of the main repo folder, then you do not need git submodule add command.
Simply add files in sub1 and sub2, and you will be able to git add and git commit them.
No submodule involved.

这篇关于如何在现有仓库中创建子模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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