简体   繁体   English

Git Subtree合并策略 - 设置本身如何跨越克隆?

[英]Git Subtree merge strategy - how does the setup itself carry over across cloning?

When someone else clones your repository that has a subtree in it created with the merge strategy, the remotes needed for updating a subtree aren't there. 当其他人克隆使用合并策略创建的子树的存储库时,更新子树所需的遥控器不存在。 Which steps of the subtree setup (following https://help.github.com/articles/working-with-subtree-merge as an example) need to be done in order to get subtree updates working after a clone? 需要完成子树设置的哪些步骤(以https://help.github.com/articles/working-with-subtree-merge为例)才能在克隆之后使子树更新正常工作?

To update the sub-tree explicitly and independently from upstream you'll need to re-add the remote as you've indicated. 要显式且独立于上游更新子树,您需要按照指示重新添加遥控器。 In the new cloned repo: 在新的克隆回购中:

$ git remote add -f <subtree-repo> <subtree-repo-url>
$ git pull -s subtree <subtree-repo> <branch>

For the link you gave it would be along the lines of, 对于您给出的链接,它将是,

$ git clone /Users/tekkub/tmp/test my-test-clone
$ cd my-test-clone
$ git remote add -f cork git://github.com/TekNoLogic/Cork.git
$ git pull -s subtree cork master

You can also use git subtree pull supported on the very latest version on git. 你也可以在git subtree pull上使用最新版本支持的git subtree pull


The dependency scenario is not clear from the question, but you can also simply pull the repo you've cloned to get all the subtree updates: 从问题中不清楚依赖关系场景,但您也可以简单地拉出已克隆的repo以获取所有子树更新:

(repo1)
(repo2 [subtree: repo1]) -- clone --> (repo3)

repo1 $ git commit ...
repo2 $ git pull -s subtree ...
repo3 $ git pull

So when repo2 updates from repo1 you can simply git pull in repo3 and you'll get all its commits. 因此,当repo2repo1更新时,您只需git pull in repo3即可获得所有提交。 And you should use the commands above the dividing line only if you intend to sever the dependency between repo3 and repo2 , otherwise if you'll both pull , push upstream and pull -s subtree it's easy to get into frequent unpleasant merges. 你应该使用的命令只有当你打算切断之间的依赖分界线上方repo3repo2 ,否则如果你俩pullpush的上游和pull -s subtree很容易陷入频繁的不愉快的合并。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM