【问题标题】:Partial subtree upstream push in GitGit中的部分子树上游推送
【发布时间】:2015-06-26 21:09:28
【问题描述】:

我在 Git 中遇到一种情况,其中我有一个核心 repo,它通过 Git 子树与其他 repo 共享/使用。在回购“项目”中,我有子树回购“核心”,在那个核心中,我做了各种提交,我已经提交并推送到“项目”。我现在想将“核心”文件夹中的这些更改推送到实际的“核心”存储库。这通常可以通过以下方式完成:

git subtree push --prefix=/core/ core-repo master

但是,“核心”文件夹中恰好有一个提交,我想将其保留在“项目”的本地。便宜的 hacky 方法是将所有内容推送到上游,然后恢复该提交。我想知道是否有更合适的方法来阻止这些特定的变化进入上游。谢谢。

【问题讨论】:

    标签: git git-subtree


    【解决方案1】:

    通常您可以通过以下方式推送到特定的提交:

    git push <remotename> <commit SHA>:<remotebranchname>
    

    这会将所有提交推送到远程分支,直到指定(包括)。

    您应该能够(但我没有测试过)也可以通过子树推送来做到这一点。比如:

    git subtree push --prefix=/core/ core-repo <commit SHA>:master
    

    在您的情况下,&lt;commit SHA&gt; 应该是您想要避免推送的提交之前的提交。
    请注意,如果您在不想推送的提交之后有提交,则必须使用 git rebase 重新排序提交。

    【讨论】:

    • 它告诉我 ':master' 看起来不像 ref。所以,看起来好像我不能使用这种语法。我做了更多的阅读并挖出了一篇文章,上面写着Another issue is, it won’t let you pick which local subtree commits to backport with git subtree push: it’s an all-or-nothing affair. This contradicts one of the key benefits of subtrees, which is to be able to mix container-specific customizations with general-purpose fixes and enhancements. 所以,我可能只需要挑选每一个提交。 medium.com/@porteneuve/mastering-git-subtrees-943d29a798ec
    • 我最终推送了所有内容,然后恢复了特定的提交。虽然现在我想如果我拉入项目 repo 中的子树,我对该 repo 的特定更改也将被还原:/
    猜你喜欢
    • 1970-01-01
    • 2020-09-26
    • 2013-04-13
    • 1970-01-01
    • 2021-12-19
    • 1970-01-01
    • 2020-03-04
    • 2020-07-23
    • 2012-11-24
    相关资源
    最近更新 更多