How do I move master back several commits in git?


I have a git repository which holds a Drupal site. I spent the last day trying to build a feature using several different modules. I have given up on my current approach and have decided to try a different combination of modules. However, my repository has several commits on the master branch that contain this feature development process (I understand that I did not branch in an effective manner.) I want to get rid of the last three or four commits and set master to that point in my history (I don’t want to merge my current work with anything, I just want it to go away.) How do I do this?


In order to do it locally, you can do the following commands to go to master and move it to the old commit.

git checkout master
git reset --hard <old_commit_id>

If you then want to push it to the remote, you need to use the -f option.

git push -f origin master

Answered By – merlin2011

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published