Git 个人文件历史丢失 git 子树

Git individual file history lost with git subtree

我正在将 2 个 git 个存储库(old1 和 old2)合并为 1 个(new1)。我的要求是合并所有分支并保留 git 提交历史记录。我可以实现的第一个,但我正在为提交历史而苦苦挣扎。

这是我执行的将旧 1 存储库合并到新 1 的子文件夹中的命令:git subtree add -P old1 https://github.com/example/old1.git master

git log --graph --oneline --decorate --all 的输出:

*   ad4fcb6 (HEAD -> master, origin/master, origin/HEAD) Add 'komed-connector/' from commit '50b42475113c295c66c4050b3b0f119a6ebff62b'
|\  
| * 50b4247 Updated komed-shared
| *   1a5435a Merge branch 'master' into openshift_build
| |\  
| | *   8aa90aa Merge branch 'r/3.4'
| | |\  
| | | * a6cea77 updated shared
| | * | a40c782 Updated komed-shared
...

到目前为止一切顺利:git 保留了提交历史记录。但是,如果我正在检查新子文件夹中单个文件的 git 提交,它不会显示所有提交:

如何将 2 个回购合并为 1 个并保留单个文件 git 提交历史记录? 所以当 运行 gitk old1/Dockerfile git 显示旧存储库上发生的所有提交。

我的理解是Git没有"individual file commit history"的概念。跟踪 old1/Dockerfile 与某个不同位置的某个其他文件相关的事实留给可视化和命令行工具(或缺乏)中的启发式方法。可以在这个问题中找到对此的更多讨论:

从实际的角度来看,我会尝试重写 "old" 回购历史,就好像它完全发生在 oldreporoot/old1 文件夹中一样。然后这个 repo 可以干净地合并到新的 repo 中,并且你的 visual/command 行工具应该相应地运行,因为文件不是 renamed/moved。

git filter-branch --tree-filter 应该有助于完成这项工作,如 https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History

中所述