简体   繁体   中英

git revert changes and cancel pull request

Unfortunately after years working with subversion, I am trying to warm up with git. The problem is as follows:

  • i forked a remote project.
  • pushed commits (which now i want to revert or simply vanish!) to my own remote.
  • pull requested with my changes in above step.

Visually it looks like;

original project:

A->B->C->D->E

my own remote fork (x,y,z are my commits to revert or delete if it's possible):

A->X->Y->Z->C->D->E

I want my forked remote to be as the same as the original remote. However After i tried reverting (with git revert [HASH]) my commits one by one and pushing those reverts to my own remote, It seems the pull request did not disappear.

The last thing would be remove my fork, and refork the original project, if i could not get a solution.

Any suggestions before doing that?

Note: in term of PR (GitHub Pull Request), you now (June 24th, 2014) can cancel a PR easily
(See also " Reverting a pull request "):

Introducing the Revert Button

you can easily revert a pull request on GitHub by clicking Revert:

https://camo.githubusercontent.com/0d3350caf2bb1cba53123ffeafc00ca702b1b164/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f68656c702f70756c6c5f72657175657374732f7265766572742d70756c6c2d726571756573742d6c696e6b2e706e67

You'll be prompted to create a new pull request with the reverted changes:

https://camo.githubusercontent.com/973efae3cc2764fc1353885a6a45b9a518d9b78b/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f68656c702f70756c6c5f72657175657374732f7265766572742d70756c6c2d726571756573742d6e65772d70722e706e67

Let's say you're on your master branch and want to erase some commits, you could git rebase -i A to run and remove the unwanted commits from your local repo. ( there are some good git rebase -i informations on GitHub )

You can then git push --force origin master:master to overwrite the remote master branch with your local one. (warning, I'm nor responsible for the lost code resulting of this :P).

For your pull request, that is more a GitHub issue than a git one, I think you can easily close it on the webpage.

FYI git revert HASH actually creates a commit that negates the patch of HASH, it do not really revert anything as you intended it ;)

Assuming you have these two remotes defined in your local repo:

  • origin: points to the original repo
  • remote2: points to your own personal fork

And you want to force update from origin/somebranch to remote2/otherbranch , you could do like this:

# make sure you have up to date branch data locally
git fetch origin
git fetch remote2

# force push to remote2 from origin
git push remote2 origin/somebranch:otherbranch --force

To reset a local branch to the same state as a remote branch:

git reset --hard origin/somebranch

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM