问题描述
在存储库 A
中,文件夹 sub
作为存储库 S
的 git 子树包含 - 指向 master
> 分支.
In a repository A
the folder sub
is included as git subtree of the repository S
- pointing to master
branch.
我已将存储库 A
分叉到 F
.现在我想在 F
中执行以下操作之一:
I have forked repository A
into F
. Now I want to do one of the following in F
:
- 更改
sub
以使用S
的不同分支(即develop
分支) - 或:更改
sub
以完全使用不同的存储库
- change
sub
to use a different branch ofS
(iedevelop
branch) - or: change
sub
to use a different repository altogether
是否有可能其中之一,如果有,如何?我应该知道有什么副作用吗?
Is either one of these possible, and if so, how? Will there be any side effects I should know of?
当我合并更改(拉取请求)时,如何确保我的子树更改不会在存储库 A
中更新?我的意思是除了隔离提交.
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.
推荐答案
如果你使用 git subtree
(而不是 git submodule
)来创建子树,那么它只是一个普通的目录.要将其切换到另一个分支,只需将其删除并从新分支重新创建子树.这是:
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 rm <subtree>
git commit
git subtree add --prefix=<subtree> <repository_url> <branch>
这应该没有问题.
这篇关于git subtree:可以更改分叉存储库中的子树分支/路径吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!