无法将现有的Git存储库添加到新的存储库中 [英] Can't add existing Git repository into new repository
问题描述
我正在尝试创建一个新的存储库并为其添加两个项目。其中一个项目已经在Git源代码控制之下,所以我复制了该项目并删除了.git文件夹并删除了它的存储库。当我将项目添加到我的存储库时,不在源代码控制下的项目会被正确添加,但另一个会作为子模块(GitHub上的绿色文件夹)被添加。
我试着通过做 git rm --cached
来移除子模块,但它仍然存在,我可以将项目的文件添加到存储库中。
您是否尝试过使用新的结帐功能?好像没有 git submodule remove
,所以你必须手动编辑 .gitmodules
。
如果您想使用签出副本将模块X(已经在版本控制下)添加到模块Y(这是新的):
.gitmodule
(如果有的话,那就更复杂了)。
git status
git clean -xfd
来清除某些中的任何内容。 .gitignore
,如临时构建文件等。
.git
目录
git add X
。
您也可以在X中执行类似于 git clone path-to-Y
的操作,然后执行 rm -rf Y / .git
。
I'm trying to create a new repository and add two projects to it. One of the projects was already under Git source control so I copied the project and removed the .git folder and deleted the repository I had for it. When I add the projects to my repository the one that wasn't under source control gets added fine but the other one gets added as a submodule (green folder on GitHub).
I tried removing the submodule by doing git rm --cached
on it, but it's still there and I can't add the files of the project to the repository.
Have you tried with fresh checkouts yet ? There seems to be no git submodule remove
, so you would have to manually edit the .gitmodules
.
If you want to add module X (which is already under version control) to module Y (which is new) using checked-out copies:
- Cd into X
- Make sure it is a stand-alone module: there shouldn't be any
.gitmodule
(if there is, then it's more complicated). - Run
git status
to make sure you don't have any uncommitted changes. - Run
git clean -xfd
to get rid of anything that's in some.gitignore
, like temporary build files, etc. - Remove the
.git
directory - Copy X into Y
- Run
git add X
inside Y.
You could also do something like git clone path-to-Y
in X followed by rm -rf Y/.git
.
这篇关于无法将现有的Git存储库添加到新的存储库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!