我有两个仓库。第一个回购(我们称其为A)是前一段时间开始的;第二个回购(B)是最近才开始的。现在我们正在考虑,我们宁愿将B设为A的子目录。所以我想这样做,但要保留B的提交历史记录。
.git
目录或类似的内容。在完成任何操作后,我希望满足三个条件:
HEAD
处看到的文件和目录在A的子目录中,即/path/to/repoB/somefile.js
在/path/to/repoA/B/somefile.js
处找到git log
等可见)一些例子可以阐明我的意图:
file.txt
file.txt
B/file.txt
B/file.txt
编辑:
已提出 Merge git repository in subdirectory作为我的问题的副本。我承认这非常接近我的要求,并且有几个很好的答案。我在那里尝试了subtree
答案,也尝试了rebase --onto
答案。两者都非常接近,但并不令人满意:subtree
不允许git log
在没有参考path/to/file/without/repo-subdir
的情况下查看整个存储库历史记录的历史记录(我将B移到repo-subdir
);并且rebase --onto
无法使A的HEAD
看到B的历史记录。
答案 0 :(得分:2)
这就是我最终要做的。感谢Freenode(IRC)中atrus
的{{1}}向我指引正确的方向。
#git
git checkout -b indir
,其中mkdir b-subdir
是我打算让B结束于A的目录树中的目录。b-subdir
将所有内容(git mv [...] b-subdir
和.git/
本身除外)移到b-subdir/
中。b-subdir
)。push -u origin HEAD
git remote add repo-b ssh://......../repo-b.git
git fetch repo-b
这使我可以查看来自存储库B(使用git merge --allow-unrelated-histories repo-b/indir
的{{1}}开关)的任意文件的完整历史记录,而无需删除{{ 1}}从文件路径开始。使用--follow
,如果您删除文件的历史记录,则只会在B中看到该文件的历史记录;否则,您只会在A中看到该文件的历史记录。