Git Revert Feature Branch From Master

In this article, We will explain how you can reset, revert your master branch changes to the previous state.

Image for post

Example Revert From Master

For example, your master branch is pointing to feature 1.2 (commit af2w4)

and you want to revert back your changes to feature 1.1 (commit wd2e4)

Delete the last commit

Deleting the last commit is a simple case. Let’s say we have a remote origin with a branch master that currently points to commit af2w4 and want to make the parent commit wd2e4

Step 1

git push origin +wd2e4^:master

Where git interprets x^ as the parent of x and + as a forced non-fast-forward push. If you have the master branch checked out locally, you can also do it in two simpler steps: First reset the branch to the parent of the current commit, then force-push it to the remote.

Step 2

git reset HEAD^ --hard

Step 3

git push origin -f

Now your master branch is pointing to feature 1.1 (commit wd2e4)

Thank You


Image for post
If you liked this post, please support our work!

Written by

We teach & develop for startups

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store