Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Revert a GitHub "squash and merge" into a regular merge commit

Tags:

git

github

When I merged https://github.com/nodemcu/nodemcu-firmware/pull/1627 a few days ago, a snap from the dev branch to the master branch, I chose "squash and merge" instead of a regular "merge commit". I can't simply revert the PR and create a new PR from dev as there have been commits to dev in the meantime.

Is there a sensible way to fix this? Maybe something like https://stackoverflow.com/a/28497372/131929?

like image 292
Marcel Stör Avatar asked Sep 19 '25 07:09

Marcel Stör


1 Answers

Although I fully agree with @torek's answer, he left out some of the details. You can indeed revert the commit on the master branch. There are two ways of doing this:

  • you can change the history and use git reset HEAD~1. This only works if you didn't commit anything else to the master branch in the meantime and you'll have to push using git push -f. Using this command will remove the commit from the history.
  • or you can use git revert REV, where REV is the hash of the commit. In this case an extra commit will be created which undoes the exact work of the commit.

Then the easiest way to have just this work in a new pull request would be to first check out the exact work you had: git checkout REV. Then you can create a new branch (git checkout -b NAME), push this branch and create a new pull request.

like image 62
Dekker1 Avatar answered Sep 22 '25 04:09

Dekker1