问题描述
如何应该我,如在最好的,最好的程序...
如果您只想将子模块代码放入主存储库中,子模块并将文件重新添加到主库:
git rm --cached submodule_path#删除对子模块的引用HEAD(没有尾部斜线)
git rm .gitmodules#如果你有多个子模块,
#你需要编辑这个文件而不是删除!
rm -rf submodule_path / .git#确保你有备份!
git add submodule_path#将添加文件而不是提交引用
git commit -mremove submodule
如果您还想保留子模块的历史记录,可以执行一个小技巧:将子模块合并到主存储库中,以便结果与以前相同,除了子模块文件现在位于主存储库中。
在主模块中,您需要执行以下操作:
#获取子模块提交到主存储库
git remote add submodule_origin git:// url / to / submodule / origin
git fetch submodule_origin
#开始假合并(不会更改任何文件,不会提交任何内容)
git merge -s我们的--no-commit submodule_origin / master
#与第一种解决方案相同
git rm --cached submodule_path#删除对子模块的引用HEAD
git rm .gitmodules#如果您有多个子模块,则
#你需要编辑这个文件而不是删除!
rm -rf submodule_path / .git#确保你有备份!
git add submodule_path#将添加文件而不是提交引用
#提交并清理
git commit -m已删除的子模块
git remote rm submodule_origin
结果库看起来有点奇怪:会有多个初始提交。但是它不会给git带来任何问题。
在第二种解决方案中,您将拥有很大的优势,即仍然可以运行git blame或git log原本是在submodules。实际上你在这里做的是重命名一个仓库中的许多文件,而git应该自动检测这个。如果git log仍然存在问题,请尝试一些选项(--follow,-M,-C),以便更好地重命名/复制检测。
How do I un-submodule a git submodule (bring all the code back into the core) ?
As in how "should" I, as in "Best procedure" ...
If all you want is to put your submodule code into the main repository, you just need to remove the submodule and re-add the files into the main repo:
git rm --cached submodule_path # delete reference to submodule HEAD (no trailing slash)
git rm .gitmodules # if you have more than one submodules,
# you need to edit this file instead of deleting!
rm -rf submodule_path/.git # make sure you have backup!!
git add submodule_path # will add files instead of commit reference
git commit -m "remove submodule"
If you also want to preserve the history of the submodule, you can do a small trick: "merge" the submodule into the main repository so that the result will be the same as it was before, except that the submodule files are now in the main repository.
In the main module you will need to do the following:
# Fetch the submodule commits into the main repository
git remote add submodule_origin git://url/to/submodule/origin
git fetch submodule_origin
# Start a fake merge (won't change any files, won't commit anything)
git merge -s ours --no-commit submodule_origin/master
# Do the same as in the first solution
git rm --cached submodule_path # delete reference to submodule HEAD
git rm .gitmodules # if you have more than one submodules,
# you need to edit this file instead of deleting!
rm -rf submodule_path/.git # make sure you have backup!!
git add submodule_path # will add files instead of commit reference
# Commit and cleanup
git commit -m "removed submodule"
git remote rm submodule_origin
The resulting repository will look a bit weird: there will be more than one initial commit. But it won't cause any problems for git.
In this second solution you will have the big advantage that you can still run git blame or git log on the files which were originally in submodules. In fact what you did here is to rename many files inside one repository, and git should autodetect this. If you still have problems with git log, try some options (--follow, -M, -C) which do better rename/copy detection.
这篇关于un-submodule一个git子模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!