【问题标题】:How to remove child commit from existing pr如何从现有 pr 中删除子提交
【发布时间】:2021-12-07 16:02:49
【问题描述】:

真的很傻,我昨天在 branch_A 上向 master 提出了 pull request。许多文件已更改,我不想添加更多文件。我从 branch_A 切换到新分支到 branch_B。我添加了我想要提交的文件,并从 branch_B 推送。

在 Github 上,如果我想将这个提交合并到 master,它表明我在一个单独的分支上所做的 pr 和这个新的提交是在一起的。我不想将此提交推送到我之前的拉取请求。因为我在一个新分支上,所以我想它会创建一种方法来发出新的拉取请求。

我应该删除提交并尝试不同的方式吗?我应该合并提交和公关吗?我应该按原样提交拉取请求吗?我应该尝试将此提交推送到 Branch_A 而不是 master?有很多问题。

下面看一下cli步骤:

  • git branch -vv (master, branch_A)
  • git checkout -b branch_B
  • git 添加。
  • git commit -m"something cool"
  • git push origin 分支_B

任何帮助都会很棒!

【问题讨论】:

    标签: git github git-commit pull-request


    【解决方案1】:

    从branch_A切换到新分支到branch_B

    在签出branch_A 的同时创建branch_B 导致branch_B 基于branch_A

    树 1

    branch_B  // <- subsequent commits to branch_B
    |
    branch_A  // <- commits to branch_A
    |
    |
    master
    

    我不想将此提交推送到我之前的拉取请求。

    如果我对你的理解正确,你宁愿这样做:

    树 2

    branch_B  // <- commits to branch_B
    |
    |   branch_A  // <- commits to branch_A
    | /
    |
    master
    

    这里对branch_B 的提交应用于master,不包括对branch_A 的更改。

    要从 Tree 1 转到 Tree 2,您需要 rebase*:

    $ git checkout branch_B
    $ git rebase master
    $ git push -f # WARNING: this command will re-write the git history for this branch.
                  # If other's use this git repo, especially if they have checked out `branch_B` locally, they should be consulted first.
    

    *使用 rebase 命令,您可以获取在一个分支上提交的所有更改并在另一个分支上重放它们。

    【讨论】:

      猜你喜欢
      • 2019-07-19
      • 2021-07-29
      • 2019-05-18
      • 2015-07-28
      • 1970-01-01
      • 2018-01-02
      • 2014-12-09
      • 2022-12-20
      • 2013-10-19
      相关资源
      最近更新 更多