【问题标题】:Move folder to another git repository and keep the history将文件夹移动到另一个 git 存储库并保留历史记录
【发布时间】:2018-09-24 15:36:29
【问题描述】:

我想将一个文件夹从 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/

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

如果可以,请告诉我。

非常感谢。

【问题讨论】:

标签: git github gitlab bitbucket


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:
    git filter-branch --subdirectory-filter src/Project/RegistrationBundle/ -- --all
    

    当您运行此命令时,您所拥有的只是 RegistrationBundle 中的文件,然后在新存储库中添加一个带有 RegistrationBundle 路径的远程,然后执行 git pull

    【讨论】:

    • 您的回答经过审核。我的评论是改进您的答案的建议。请点击上方的“编辑”并添加您提供的说明。不要在 cmets 中解释,因为 cmets 可以随时删除。
    • 这个命令有一个警告:警告:git-filter-branch 有大量的陷阱会产生错误的历史重写。在继续中止之前按 Ctrl-C,然后使用替代过滤工具,例如 'git filter-repo' (github.com/newren/git-filter-repo)。
    猜你喜欢
    • 2013-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-21
    • 2012-05-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多