Git-如何将分支拆分为其自己的存储库? [英] Git - How to split a branch to it's own repository?
问题描述
我有一个存储库,其中某个分支( admin
)已从 develop
分支出来.看起来大概是这样
I have a repository where a branch (admin
) has been branched out from develop
at some point. It looks roughly like this
develop c2 c4 c5
*------------*---------*---------*------------...
c1 \
\____________________*c3
admin
我希望developer分支保持不变,而admin分支应该拥有自己的存储库.作为记录,我使用的是sourcetree + bitbucket.
I want the develop branch to stay the same and admin branch should have it's own repository. For the record, I'm using sourcetree+bitbucket.
我尝试了此答案,并尝试了 git push url://to/new/repository.git admin:develop
.在我的新仓库中,它的历史是从对开发(c1)的第一次提交开始的.在新的存储库中看起来像这样.
I tried the method mentioned in this answer and tried git push url://to/new/repository.git admin:develop
. What it did in my new repo is that the history started from the first commit of develop (c1). it looks like this in the new repository.
c1 c2 c3
*-------*----------------------------*
develop
但是我想从c2启动这个新的存储库.这是正常行为还是我做错了什么?达到预期效果的正确方法是什么?
I wanted to start this new repository from c2 however. Is it normal behavior or have I done somthing wrong? What's the correct way to achieve desired result?
推荐答案
git checkout -b sliced-admin admin # start with admin
git rev-list develop.. | tail -1 >.git/info/grafts # slice out the develop history
git filter-branch # .
rm .git/info/grafts # .
现在将sliced-admin分支推到您想要的任何地方
Now push the sliced-admin branch wherever you want
git push u://r/l sliced-admin:itsnamethere
这篇关于Git-如何将分支拆分为其自己的存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!