删除 git 子模块但保留文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26752481/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:31:15  来源:igfitidea点击:

remove git submodule but keep files

git

提问by Askbar

I have a git submodule that I would like to become part of my main project (since I have a lot of project specific code that will go into the submodule).

我有一个 git 子模块,我希望它成为我主项目的一部分(因为我有很多项目特定的代码将进入子模块)。

So I'd like to remove the git references to the submodule and add the files to my main git repository.

所以我想删除对子模块的 git 引用,并将文件添加到我的主 git 存储库中。

But how ?

但是怎么样?

回答by VonC

You must remove the gitlink entryin your index:

您必须删除索引中的gitlink 条目

mv subfolder subfolder_tmp
git submodule deinit subfolder
git rm --cached subfolder
mv subfolder_tmp subfolder
git add subfolder

Replace subfolderwith the name of the folder for your submodule, and make sure to not add any trailing slash.

替换subfolder为子模块的文件夹名称,并确保不添加任何尾部斜杠。

This is what I detail in "Remove a Git submodule?" and "un-submodule a git submodule".

这是我在“删除 Git 子模块?”和“取消子模块 git 子模块”中详细说明的内容。

The --cachedoption allows you to keep the subfolder content in your disk... except git submodule deinitwould already have removed that content anyway. Hence the mvpart.

--cached选项允许您将子文件夹内容保留在磁盘中...除非git submodule deinit无论如何已经删除了该内容。因此mv部分。

You then can add and commit that subfolder.

然后,您可以添加并提交该子文件夹。

回答by fractos

The answer from VonC will delete the submodule folder contents unless you rename the physical folder first - as shown in this answer, whose question was noted to be a duplicate by Chad:

除非您先重命名物理文件夹,否则 VonC 的答案将删除子模块文件夹内容 - 如本答案所示,乍得指出其问题是重复的:

https://stackoverflow.com/a/16162228

https://stackoverflow.com/a/16162228