首页 > 解决方案 > 将文件夹移动到另一个 git 存储库并保留历史记录

问题描述

我想将一个文件夹从 git 移动到另一个 git 存储库。

例如:

这是我在 Git 中当前的文件夹结构。

src/Project/RegistrationBundle
src/Project/PictureGenerationBundle
src/Project/CloudDriveBundle
readme.md

我想将它移动到具有以下文件夹结构的新存储库,但我想保留以前存储库中的 git 历史记录:

src/RegistrationBundle
readme.md

我试图用 git filter-branch 运行它

git filter-branch --subdirectory-filter src/Project/RegistrationBundle/

但是,我找不到自定义文件夹结构的解决方案。

请让我知道它是否可以实现。

非常感谢。

标签: gitgithubgitlabbitbucket

解决方案


您可以更改当前本地存储库上的存储库架构(删除“项目”文件夹),提交更改,然后更改远程 git 存储库。

用于git remote set-url origin <the new git url>更改存储库 url。

历史将是相同的,因为 .git 文件夹中的本地历史根本没有改变。


推荐阅读