Reputation: 73
I made some changes to a package on Github and I send a pull request. The author decided not to merge my changes so I left with different copy of the package. How to revert my changes and create another pull request with new code but without pushing the rejected code?
Upvotes: 0
Views: 2073
Reputation: 1239
I had local commits that I wanted to push to my repository, but then I realized I still have old commits that were rejected in a previous pull request so I need to undo them before I push.
What I did:
git checkout -b reverting_changes_branch
git reset --hard upstream/master
git push -f origin master
This was my safe way to do it, maybe there is a simpler way.
Upvotes: 0
Reputation: 41
From your master head, which upstream didn't want
$ git checkout -b myunwantedbranch
$ git checkout master
$ git reset --hard upstream/master
Your local changes are now on the branch myunwantedbranch, and your master's the same as upstream. (Effectively you're creating the proper name for this branch, then rewinding all the unwanted stuff out of the master branch.)
Note - I'm a git newb, this is how I did the task when faced with an almost identical problem - if it's wrong, please please please correct me.
Upvotes: 4
Reputation: 17674
Supposing that the original repository(the one you forked from) is kept in track with a remote named upstream, you can,
git checkout upstream/master
git checkout -b <new-branch>
So you'll have a new branch with name which has a "starting-point" the state where the master branch of the original repository is.
If the original repository was updated since, you may want to do a fetch first
git fetch upstream master
git checkout FETCH_HEAD # or upstream/master
git checkout -b <new-branch>
Moreover, if you don't care about your changes, and would like to get rid of them altogether, you can simply run
git reset --hard upstream/master # go back to where you were
# before and changes were made
git pull upstream # update your repository
note that this last code snippet will remove your changes, and they'll be lost. So use it only if you know what you're doing.
EDIT:
I just saw Dogbert's comment. That link describes how you can get the upstream master branch and get your changes incorporated from that point. I explained how to create a new branch that's synced with upstream's master branch. So, I'm not really sure what you need now.
Upvotes: 1