How to revert pushed commits?

There are two ways you can do this.

  1. You can just remove everything and come back to the old state which is proper as per you.
  2. Revert the changes which you have made.

For the 1st Solution, you can use the following commands:

git reset --hard <commit-id>

This will bring the Head for the branch in you are currently to that specific “commit-id” which as per you is correct and proper.

git push -f origin <branch-name>

This command will forcefully push to the branch you are in. The combination of this command and the above command can enable you to remove all the unnecessary commits you have in your branch starting from the very top and till this “commit-id”

Note: This won’t remove the “commit-id” everything up till the “commit-id” will be removed from your branch.

For the 2nd Solution, you can use the following commands:

git revert <commit-id>

This command is used to revert the specific “commit-id” you are trying to undo.

If by mistake you have merged another branch into your different branch then you can use this command to revert the merge request:

git revert -m 2 <commit-id>

This command is used to revert or remove all the changes that took place in the merge commit “commit-id”. This will allow reverting the merge commit “commit-id”, also it will remove all the commit’s changes which came with this merge. But it won’t remove the commits which came with the merge

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)