There can be cases where you want to revert a branch or commits in git but due to many other commits on the top of it, Github does not show revert button for branch/commits or does not allow to revert due to other commits on the top of it.
(The Github User Interface where it is quick and easy to revert anything from revert button)
So in that case, specific commits/branch can be reverted from the command line to solve this problem.
Below are the steps to revert a commit:
- Check out the branch from where you want to revert the commit and rebase the branch. Here I am taking a master branch.
git checkout master
git pull –rebase origin master
- Create a new branch and switch to a new branch ‘revert_pull_request’
git checkout -b revert_pull_request
- Revert the commit. need to specify -m 1 because it is a merge commit:
git revert -m 1 6956d588g3
- Push your changes:
git push origin revert_pull_request
- Now you can merge the new branch to the master branch to revert the changes done in a commit.