I have merged a Pull Request with "Merge pull request" option on GitHub instead of using "Squash and merge". I want to revert this merge so that I can do "Squash and merge", the intention behind this step is to make the commit logs cleaner.
Asked
Active
Viewed 527 times
0
-
There should be a revert button on GitHub AFAIK. – Tim Biegeleisen Dec 11 '18 at 06:35
-
That doesn't clean up the commit logs, it just removes the changes. – Arpit Jaiswal Dec 11 '18 at 06:41
-
Why should the logs be cleaned? A revert commit is a _new_ commit, so the merge commit and its logs should still be there. – Tim Biegeleisen Dec 11 '18 at 06:43
-
@TimBiegeleisen: I wanted to undo the commit because I wanted to remove the messy commit logs and represent them by just one commit. – Arpit Jaiswal Dec 11 '18 at 11:17
1 Answers
1
In your local checkout of the repo,
git reset --hard HEAD~1
This un-does the merge in your local repo, and you can now force push it to github.
Note that you will be modifying published history in this case (it is the only way), and you should be aware of and be ready to accept the implications of it.
Other consequences of `git push --force`?
(In short, if someone had pulled the post-merge state of the repo, you've now alienated them)

stellarhopper
- 660
- 5
- 10
-
Thanks. I thought "git reset --hard HEAD~1" would not remove all the commit logs but it did. This is what I needed. – Arpit Jaiswal Dec 11 '18 at 11:16