提取 git 存储库的一部分?
假设我的 git 存储库具有以下结构:
/.git
/Project
/Project/SubProject-0
/Project/SubProject-1
/Project/SubProject-2
并且该存储库有相当多的提交。现在,其中一个子项目 (SubProject-0) 变得相当大,我想将 SubProject-0 取出并将其设置为一个独立项目。是否可以从父 git 存储库中提取涉及 SubProject-0 的所有提交历史记录并将其移动到新的存储库?
Assume my git repository has the following structure:
/.git
/Project
/Project/SubProject-0
/Project/SubProject-1
/Project/SubProject-2
and the repository has quite some commits. Now one of the subprojects (SubProject-0) grows pretty big, and I want to take SubProject-0 out and set it up as a standalone project. Is it possible to extract all the commit history involving SubProject-0 from the parent git repository and move it to a new one?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅http://git-scm.com/docs/git-filter-branch
我认为你需要类似
存储库克隆的东西。
See http://git-scm.com/docs/git-filter-branch
I think you need something like
in a clone of the repository.
我需要做类似的事情,但我想本质上将子项目从一个存储库移动到另一个存储库。我所做的是使用 fetch,因为它可以从任何来源获取对象。
因此,基本上,我创建了一个新分支,删除了该分支中不需要的内容,然后使用 git fetch 将分支从一个存储库拉到另一个存储库。一旦我有了对象,合并就成功了。
例如,
在包含原始内容的存储库上:
然后您可以将该分支从一个存储库获取到另一个完全不同的存储库(不相关):
其中 temp:temp 表示“在源上获取临时并将其保存为此处的临时”。从那里您可以将结果合并到您的母版中。
然后,您可以删除临时分支,因为在第一种情况下,您不想将其与原始存储库合并,而在第二种情况下,您已将其合并。
我确信这些步骤可以稍微压缩一下,但是这套看起来很好而且很清晰。
I needed to do something similar, but I wanted to essentially move a subproject from one repo to another. What I did instead was to use fetch, since it can fetch objects from any source.
So, basically, I created a new branch, deleted the unneeded stuff in that branch, then used git fetch to pull the branch from one repo to another. Once I had the objects, merge did the trick.
E.g.
On the repository that has the original stuff:
Then you can fetch that branch from one repository into a completely different one (unrelated):
where temp:temp means "fetch temp on the source and save it as temp in here". From there you can merge the result into your master.
You can then delete the temp branches, since in the first case it isn't something you ever want to merge with the original repo, and in the second case you have merged it.
I'm sure these steps could be compressed a bit, but this set seems nice and clear.