Reputation: 57893
I have a pull request here, and when I did "git rebase", it added commits that I didn't author into the pull request. The remote branch I'm merging is ahead of all of those commits so I don't understand why they are getting into 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
Upvotes: 0
Views: 267
Reputation: 31
Welcome to my life every time I rebase. Hopefully we can both avoid this in the future by listening to Olivier and not pulling. 🤞
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. You can delete the commits.
git log
will give you a list of commits. You can then grab the SHAs and remove individual commits using this:
git rebase -p --onto 4196caae8735bb983a2a0bace6f72b0820a755c1^ 4196caae8735bb983a2a0bace6f72b0820a755c1
(Note: if you're using zsh, you'll need to backwack the ˆ
. Also note that that's the same SHA repeated twice.)
Once you've killed the commit(s), you can't simply git push
, because the remote branch still has those extra commits. Instead, do the potentially-dangerous git push origin -f
to force the remote branch to match yours (rather than the other way around).
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.
Upvotes: 0
Reputation: 1115
While rebasing, you did a git pull
after your git rebase --continue
.
This will merge new commits from the origin/master branch with your local branch, and so includes the merged commits in your pull request.
After rebasing you should just push the changes to the branch you will use for the Pull Request.
Upvotes: 2