简体   繁体   中英

Reverting commits on GitHub

I have a set of commits (published) 10+ which I want to remove. So ideally I wanted to create a Pull Request which could then be merged to the develop branch of my project.

The problem is that if I am doing:

  1. git reset --hard <commit_hash>
  2. git checkout -b my_fixed_branch
  3. git push origin my_fixed_branch

The pull request on github does not show anything in diff... (As I understand it happens because the develop branch already contains changes from <commit_hash> ). So I don't really understand how to do the resetting properly...

Of course I think it's possible to do something like

  1. git reset --hard <commit_hash>
  2. git push origin develop -f

To directly override changes on develop branch... but I would want to use Pull Request instead.

This reverts every commit after (not including) <commit_hash> until now:

git revert --no-commit <commit_hash>..HEAD
git commit -m "Message explaining what was done"

The --no-commit option makes sure you get a single revert commit instead of several.

You can revert without it to create separate revert commits for each merge. This might be clearer for other users and then Git gives you the commit messages for free.

Either you revert the commits (ie creating new commits that undo the changes, using git revert ), so they can be merged (possibly through a pull request ).

Either you discard them, but then there is nothing to merge: you need to force push (by executing exactly the commands you provide in your question).

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