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:
git reset --hard <commit_hash>git checkout -b my_fixed_branchgit 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
git reset --hard <commit_hash>git push origin develop -f
To directly override changes on develop branch... but I would want to use Pull Request instead.
-
are you looking for the git revert command ? git-scm.com/docs/git-revertArchiFloyd– ArchiFloyd2017年01月25日 22:39:05 +00:00Commented Jan 25, 2017 at 22:39
2 Answers 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.
1 Comment
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).