git subtree:可以更改分叉存储库中的子树分支/路径吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18536279/
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
git subtree: possible to change subtree branch/path in a forked repository?
提问by LearnCocos2D
In a repository A
the folder sub
is included as git subtree of the repository S
- pointing to master
branch.
在存储库中,A
该文件夹sub
作为存储库的git 子树包含S
- 指向master
分支。
I have forked repository A
into F
. Now I want to do one of the following in F
:
我已将存储库分叉A
到F
. 现在我想在以下内容中执行以下操作之一F
:
- change
sub
to use a different branch ofS
(iedevelop
branch) - or: change
sub
to use a different repository altogether
- 更改
sub
为使用不同的分支S
(即develop
分支) - 或:更改
sub
为完全使用不同的存储库
Is either one of these possible, and if so, how? Will there be any side effects I should know of?
其中任何一个是否可能,如果是,如何?我应该知道有什么副作用吗?
And how can I make sure my subtree change won't be updated in repository A
when I merge my changes (pull request)? I mean besides isolating commits.
A
当我合并更改(拉取请求)时,如何确保我的子树更改不会在存储库中更新?我的意思是除了隔离提交。
回答by elmart
If you used git subtree
(and not git submodule
) to create the subtree, then it's just a normal dir. To switch it to another branch, just delete it and recreate the subtree from the new branch. This is:
如果你使用git subtree
(而不是git submodule
)来创建子树,那么它只是一个普通的目录。要将其切换到另一个分支,只需将其删除并从新分支重新创建子树。这是:
git rm <subtree>
git commit
git subtree add --prefix=<subtree> <repository_url> <branch>
That should work without problems.
这应该没有问题。