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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:59:21  来源:igfitidea点击:

git subtree: possible to change subtree branch/path in a forked repository?

gitmergerepositorygit-subtree

提问by LearnCocos2D

In a repository Athe folder subis included as git subtree of the repository S- pointing to masterbranch.

在存储库中,A该文件夹sub作为存储库的git 子树包含S- 指向master分支。

I have forked repository Ainto F. Now I want to do one of the following in F:

我已将存储库分叉AF. 现在我想在以下内容中执行以下操作之一F

  • change subto use a different branch of S(ie developbranch)
  • or: change subto 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 Awhen 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.

这应该没有问题。