如何将我的 git 项目移动到所有提交的子目录,一个文件除外?

How do I move my git project to a subdirectory for all commits, except one file?

我正在尝试将我的整个存储库根目录移动到一个子目录中,除了一个文件之外的所有内容。

例如,我有这样的东西:

root
-Folder1
-Folder2
-.gitattributes

对于所有提交和历史记录,我想要

root
-ProjectA
--Folder1
--Folder2
-.gitattributes

即,我想将所有内容 除了 .gitattributes 移动到子目录。如果我使用

 git filter-repo --to-subdirectory-filter ProjectA/

一切都被移动了。除了单个文件,我找不到移动所有内容的策略。

如何将文件保存在原处?或者我如何使用另一个命令将该文件移回根目录?

如果可以,您将列出除 .gitattributes 之外的所有元素,并使用 path renaming:

在一个命令中重命名它们
git filter-repo --path-rename Folder1:ProjectA/Folder1 \
                --path-rename Folder2:ProjectA/Folder2 \
                ...

OP House suggests in 更明智的做法:

  • 将所有内容移动到子目录,
  • 然后将 .gitattributes 移回 --path-rename ProjectA/.gitattributes:.gitattributes

我会在单独克隆的存储库中执行每个步骤,以确保在失败时我可以返回到原始存储库。
第二步将在第一步的存储库克隆中完成。