[英]Doing rebase adds replays master branch commits into my Pull Request
I have a pull request here , and when I did "git rebase", it added commits that I didn't author into the pull request. 我在这里有一个拉取请求,当我执行“ git rebase”时,它添加了我未编写的提交到拉取请求中。 The remote branch I'm merging is ahead of all of those commits so I don't understand why they are getting into PR.
我要合并的远程分支位于所有这些提交之前,因此我不明白他们为什么进入PR。 Any idea how to undo this, or how to prevent this in the future?
知道如何撤消此操作,或将来如何防止此操作?
Here's what I did 这就是我所做的
# 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
After this, my pull request contains changes in master branch that I didn't author 之后,我的拉取请求包含我未编写的master分支中的更改
While rebasing, you did a git pull
after your git rebase --continue
. 在重新设置基准时,您在
git rebase --continue
之后进行了git pull
。
This will merge new commits from the origin/master branch with your local branch, and so includes the merged commits in your pull request. 这会将来自origin / master分支的新提交与您的本地分支合并,因此将合并的提交包括在请求请求中。
After rebasing you should just push the changes to the branch you will use for the Pull Request. 重新设定基准后,您只需将更改推送到将用于“拉取请求”的分支即可。
Welcome to my life every time I rebase. 欢迎我每次改建生活。 Hopefully we can both avoid this in the future by listening to Olivier and not pulling.
希望我们将来都可以通过听Olivier而不是拉扯来避免这种情况。 🤞
🤞
But, okay, you already did this and now you're in a mess. 但是,好的,您已经这样做了,现在您一团糟。 What do?
做什么? I used to just create a new branch, copy over my changes, and make a new PR, but we don't have to live life this way.
我以前只是创建一个新分支,复制所做的更改,然后进行新的PR,但我们不必这样生活。 You can delete the commits.
您可以删除提交。
git log
will give you a list of commits. git log
将为您提供提交列表。 You can then grab the SHAs and remove individual commits using this: 然后,您可以使用以下方法获取SHA并删除单个提交:
git rebase -p --onto 4196caae8735bb983a2a0bace6f72b0820a755c1^ 4196caae8735bb983a2a0bace6f72b0820a755c1
(Note: if you're using zsh, you'll need to backwack the ˆ
.) git rebase -p --onto 4196caae8735bb983a2a0bace6f72b0820a755c1^ 4196caae8735bb983a2a0bace6f72b0820a755c1
(注:如果您使用的zsh,你需要backwack的ˆ
Once you've killed the commit(s), you can't simply git push
, because the remote branch still has those extra commits. 一旦杀死了提交,就不能简单地
git push
,因为远程分支仍然具有这些额外的提交。 Instead, do the potentially-dangerous git push origin -f
to force the remote branch to match yours (rather than the other way around). 相反,执行潜在危险的
git push origin -f
强制远程分支与您的分支匹配(而不是相反)。
Disclaimer: I don't know what I'm doing. 免责声明:我不知道我在做什么。 But after a few attempts attempts, I got to the state I wanted by doing these things.
但是经过几次尝试,我通过做这些事情达到了想要的状态。
Props to Seth Robertson git choose-your-own-adventure for the "cherry-pitting" command. 塞斯·罗伯森(Seth Robertson)的道具git为“樱桃进站”命令选择了自己的冒险方式 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.