做 rebase 将重播主分支提交添加到我的合并请求中

Doing rebase adds replays master branch commits into my Pull Request

我有一个 pull request here, and when I did "git rebase", it added commits that I didn't author into the pull request. The remote branch 我正在合并是在所有这些提交之前,所以我不明白他们为什么要进入 PR。知道如何撤消此操作,或将来如何防止此操作吗?

这是我所做的

# Checkout local branch and apply changes
mkdir /home/yaroslavvb/tfimmediate_fresh
cd /home/yaroslavvb/tfimmediate_fresh
git clone https://github.com/yaroslavvb/tensorflow.git
cd tensorflow
git checkout tfimmediate_fresh
# do my modifications
git commit -m "Changes"

# Rebase against main branch
git remote add tfmain https://github.com/tensorflow/tensorflow.git
git fetch tfmain
git rebase tfmain/master

# fix conflicts
git add tensorflow/contrib/__init__.py
git rebase --continue
git pull
# fix conflicts again
git add tensorflow/contrib/__init__.py
git commit -m "Fix merge conflicts"
git push
git push -f

在此之后,我的拉取请求包含主分支中不是我创作的更改

在变基时,您在 git rebase --continue 之后做了 git pull

这会将来自 origin/master 分支的新提交与您的本地分支合并,因此将合并的提交包含在您的拉取请求中。

变基后,您应该将更改推送到您将用于合并请求的分支。

欢迎来到我每次变基的生活。希望我们将来都能通过听取 Olivier 的意见而不是拉扯来避免这种情况。

但是,好吧,你已经这样做了,现在你一团糟。做什么?我过去只是创建一个新分支,复制我的更改,然后创建一个新的 PR,但我们不必以这种方式生活。您可以删除提交。

git log 会给你一个提交列表。然后,您可以获取 SHA 并使用以下方法删除单个提交:

git rebase -p --onto 4196caae8735bb983a2a0bace6f72b0820a755c1^ 4196caae8735bb983a2a0bace6f72b0820a755c1(注意:如果您使用的是 zsh,则需要倒退 ˆ。另请注意,相同的 SHA 重复了两次。)

一旦你杀死了提交,你就不能简单地git push,因为远程分支仍然有那些额外的提交。相反,执行具有潜在危险的 git push origin -f 以强制远程分支与您的相匹配(而不是相反)。

免责声明:我不知道自己在做什么。但是经过几次尝试后,我通过做这些事情达到了我想要的状态。

支持 Seth Robertson git choose-your-own-adventure for the "cherry-pitting" 命令。