在根目录中新建一个git存储库,以便在子目录中包含存在的存储库 [英] New git repository in root directory to subsume an exist repository in a sub-directory

查看:563
本文介绍了在根目录中新建一个git存储库,以便在子目录中包含存在的存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个目前不受任何版本控制的大代码库(是的,真的)。我一直在研究深层目录中的一个组件,并创建了一个隐藏的git存储库来跟踪我的更改。
我现在想要将所有的代码添加到源代码控制中,并为整个目录树创建一个存储库。我希望新的外部存储库将文件的所有历史记录包含在内部存储库中。
我不想单独的项目或子模块;我想要知道存储库是从一开始就在代码树的根目录中创建的,并且内部存储库从不存在。
我想删除子目录中的.git目录,但不希望丢失它包含的修订历史记录。

I am working on a large code base that is not currently under any revision control (yes, really). I have been working on one component in a deep directory and created a covert git repository to track my changes. I now want to add all the code to source control and make a repository for the whole directory tree. I want the new, outer repository to include all the history for the files in the inner repository. I do not want separate projects or submodules; I want to be as if the repository had been created in the root of the code tree from the start and the inner repository never existed. I want to delete the .git directory in the sub-directory but would prefer not to lose the revision history that it contains.

我读过的所有内容这个话题是关于合并现有的仓库,这里不是这种情况,或者关于维护子模块或远程项目,我不想这样做。

Everything I have read on the topic is about merging existing repositories and that is not the case here or about maintaining submodules or remote projects, which I don't want.

谢谢。

推荐答案

假设您的组件位于 / project-root / deep / path / to / component 。下面的命令可以完成你想要的功能:

Let's say your component is in /project-root/deep/path/to/component. The following commands will do what you want:

cd /project-root/deep/path/to/component
git filter-branch --tree-filter 'mkdir -p deep/path/to/component; git mv file1 file2 file2 deep/path/to/component' HEAD
rm -rf deep
mv .git /project-root
git reset --hard

当然,您必须像平常一样为项目的其余部分添加文件。

Then of course you have to add the files for the rest of the project just as normal.

这篇关于在根目录中新建一个git存储库,以便在子目录中包含存在的存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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