且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法将现有的Git存储库添加到新的存储库中

更新时间:2023-12-01 08:20:40

您是否尝试过使用新的结帐功能?好像没有 git submodule remove ,所以你必须手动编辑 .gitmodules



如果您想使用签出副本将模块X(已经在版本控制下)添加到模块Y(这是新的):


  • 将Cd添加到X中

  • 确保它是一个独立模块:不应该有任何 .gitmodule (如果有的话,那就更复杂了)。

  • 运行 git status
  • 运行 git clean -xfd 来清除某些中的任何内容。 .gitignore ,如临时构建文件等。

  • 删除 .git 目录

  • 将X复制到Y

  • 在Y中运行 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.