git将旧存储库的一部分移动到新的存储库

时间:2012-10-19 13:46:51

标签: git repository sparse-checkout

我有一个存储库,它在根目录中包含几个目录,例如

gitroot/a
gitroot/b
gitroot/c

我想从a的内容创建一个新的git存储库,同时保留其历史记录。这可能吗?我看过稀疏的结账,但我不确定如何使用它从子目录创建一个全新的存储库(具有相关历史记录)。

1 个答案:

答案 0 :(得分:2)

克隆现有存储库后,您可以使用filter-branch

git filter-branch --subdirectory-filter a -- --all

之后;

git clean -d -f  // Remove untracked files from the working tree
git gc --aggressive // Cleanup unnecessary files and optimize the local repository
git prune  // Prune all unreachable objects from the object database
相关问题