1

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.

Harald Nordgren
12.6k7 gold badges49 silver badges70 bronze badges
asked Jan 25, 2017 at 22:32
1

2 Answers 2

2

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.

answered Jan 25, 2017 at 22:47
Sign up to request clarification or add additional context in comments.

1 Comment

Well I am doing it like: ```git revert --no-commit <hash>..HEAD and getting error: Commit <other_hash> is a merge but no -m option was given. fatal: revert failed
0

Either you revert the commits (i.e. 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).

answered Jan 25, 2017 at 22:39

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.