使用历史导出 Git 中的子树

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1662753/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:55:30  来源:igfitidea点击:

Export subtree in Git with history

gitimportexporthistory

提问by matpie

I have a folder in my Git repository that I'd like to move out in to its own repository. Is it possible to move the history of that folder along with the folder?

我的 Git 存储库中有一个文件夹,我想将它移到它自己的存储库中。是否可以随文件夹移动该文件夹的历史记录?

I've previously been doing just a git rm -r --cached subfolder/and then git initon the subfolder. However, the history is not imported in to the new repository.

我以前一直在做一个git rm -r --cached subfolder/然后git init在子文件夹上。但是,历史不会导入到新的存储库中。

回答by jamessan

Quoting an example from git-filter-branch(1)

引用一个例子 git-filter-branch(1)

To rewrite the repository to look as if foodir/ has been its project root, and discard all other history:

重写存储库以使其看起来好像 foodir/ 已经是它的项目根目录,并丢弃所有其他历史记录:

git filter-branch --subdirectory-filter foodir -- --all

Thus you can, e.g., turn a library subdirectory into a repository of its own. Note the -- that separates filter-branch options from revision options, and the --all to rewrite all branches and tags.

例如,您可以将库子目录转换为它自己的存储库。请注意将过滤器分支选项与修订选项分开的 --,以及用于重写所有分支和标签的 --all。