在历史上出口Git的子树 [英] Export subtree in Git with history

查看:139
本文介绍了在历史上出口Git的子树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我的Git仓库里的一个文件夹,我想把它移到自己的仓库里。我可以将该文件夹的历史记录与文件夹一起移动吗?



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

解决方案

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


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




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




因此,您可以将库子目录转换为自己的存储库。请注意 - 将过滤器分支选项与修订选项分开,并且 - 重写所有分支和标记。



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?

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

解决方案

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

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

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.

这篇关于在历史上出口Git的子树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆