我可以将存储库的 .git 目录移至其父目录吗?
我有两个子目录,每个子目录都有一个存储库,因此:
PPP/
|--ABC/
| |--.git/
| |--AAA/
| | BBB/
| | CCC/
|
|--DEF/
| |--.git/
| |--DDD/
| |--EEE/
并且想将它们组合成一个存储库,因此,我假设目录结构如下:
PPP/
|--.git/
|--ABC/
| |--AAA/
| |--BBB/
| |--CCC/
|
|--DEF/
| |--DDD/
| |--EEE/
这可能吗?
目前也有几个人在他们的机器上拥有该存储库。 这会让生活变得多么复杂?
塔。
I have two sub-directories each with a repo, thus :
PPP/
|--ABC/
| |--.git/
| |--AAA/
| | BBB/
| | CCC/
|
|--DEF/
| |--.git/
| |--DDD/
| |--EEE/
And would like to combine them into one repo, so, I would assume the directory structure would be like this:
PPP/
|--.git/
|--ABC/
| |--AAA/
| |--BBB/
| |--CCC/
|
|--DEF/
| |--DDD/
| |--EEE/
Is this posible?
Also currently several people have the repos on their machines. How much more complicated does that make life?
Ta.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以执行您所描述的操作,如下所示:
将
ABC
的内容移动到ABC/
子目录,并修复历史记录,使其看起来始终如此去过那里:现在您的目录结构为
ABC/ABC/your_code
与
DEF
的内容相同:现在你的目录结构是
DEF/DEF/your_code
最后,创建
PPP
存储库并将ABC
和DEF
拉入其中:现在您已拥有
PPP/ABC/your_code
和PPP/DEF/your_code
以及所有历史记录。您可能应该要求同事在他们的系统上运行前面的命令,以便每个人都能同步。
You can do what you are describing like this:
Move the content of
ABC
to anABC/
subdirectory, and fix the history so that it looks like it has always been there:Now your directory structure is
ABC/ABC/your_code
Same for the content of
DEF
:Now your directory structure is
DEF/DEF/your_code
Finally, create the
PPP
repository and pull bothABC
andDEF
into it:Now you have
PPP/ABC/your_code
andPPP/DEF/your_code
, along with all the history.You should probably ask you collegues to run the previous commands on their system, in order for everyone to be synchronized.
您真的需要将两个现有存储库合并到一个存储库中,还是只想将它们分组?
如果您只想将它们分组,那么 git-submodule 将执行您想要的操作:您最终会得到三个存储库,其中顶级存储库链接到当前两个存储库。
作为指导:
如果您要增加它们之间的耦合,则应该将它们合并到单个存储库中,以便将一个版本的存储库 A 与不同版本的存储库 B 一起使用不再有意义。
您应该使用子模块如果它们保持某种程度的独立(有时单独处理一个是有意义的),但您希望能够方便地与它们一起工作(例如一次下载两者,检查两者之间的已知良好状态等)。
使用子模块将避免存储库现有副本出现问题,因为历史记录不会改变。 合并它们将创造一个新的历史,并且从现有分支工作的人们将更难合并他们的更改。
Do you really need to merge the two existing repositories into one repository, or do you just want to group them?
If you just want to group them, then git-submodule will do what you want: you'll end up with three repositories where the top-level one links to the current two.
As a guide:
You should merge them into a single repository if you're going to increase the coupling between them so that it no longer makes sense to use one version of repo A with a different version of repo B.
You should use submodules if they remain somewhat separate (it would sometimes makes sense to work on one in isolation), but you want the convenience of being able to work with them together (e.g. download both at once, checkpoint known-good states across both, etc).
Using submodules will avoid problems with existing copies of the repositories, since the history doesn't change. Merging them will create a new history and it will be harder for people working from the existing branches to merge their changes.
(2022) 答案:考虑
git filter-repo
而不是git filter-branch
。filter-repo
速度要快得多,是此类情况的推荐方法。示例用例:
示例命令(重命名 baseDir 中的所有提交并将它们移动到 /android/path/to/file
文档:https://github.com/newren/git-filter-repo
(2022) answer: consider
git filter-repo
overgit filter-branch
.filter-repo
is much faster and is the recommended approach for something like this.Example use case:
Example command (which renames all commits from the baseDir and moves them into the /android/path/to/file
Documentation: https://github.com/newren/git-filter-repo
对我来说,似乎很难按照你想要的方式去做,因为两个项目的历史不会合并。
我最好的建议是创建一个新的存储库来包含 ABC 和 DEF,保留这两个存储库中的旧存储库以进行历史备份并通过这个新项目开始新的历史记录。
For me it seems hard to do the way you want it because the history of both project won't merge.
My best advice would be to create a new repository to contain ABC and DEF, keeping old repo from these two to have history backup and start a fresh history with this new project.