【问题标题】:Pull request contains my commits on other branch?拉取请求包含我在其他分支上的提交?
【发布时间】:2020-05-22 00:26:15
【问题描述】:

我知道这个不断变化的分支基础技巧并且它不起作用,来自这个问题:GitHub pull request showing commits that are already in target branch

在我的情况下,在切换到分支之前,我正在从我工作的其他分支获取我的提交。我该如何解决这个问题?

【问题讨论】:

    标签: git github git-commit git-pull


    【解决方案1】:

    一个相对简单的解决方案是从master(或您要合并的分支)创建一个完整的新分支,然后从旧的中逐一挑选您想要包含在 PR 中的提交分支。然后你需要使用原始分支名称强制推送到github。

    git checkout -b new_attempt origin/master
    git cherry-pick <commit1>
    git cherry-pick <commit2>
    ...
    git push --force origin new_attempt:mybranch
    

    mybranch 是您用于此 PR 的分支的名称。

    如果提交太多,您可以尝试使用 --onto 选项进行 rebase。

    git rebase --onto origin/master <base_commit> mybranch
    git push --force origin mybranch
    

    &lt;base_commit&gt; 是您要从 PR 中排除的最后一个提交。变基可能有点棘手,所以请备份并阅读git-rebase docs

    【讨论】:

      猜你喜欢
      • 2014-10-30
      • 2013-01-16
      • 1970-01-01
      • 1970-01-01
      • 2017-02-13
      • 2013-03-26
      • 1970-01-01
      • 2017-03-17
      • 1970-01-01
      相关资源
      最近更新 更多