Git How to Remove/Delete/Destroy Commit and All His Changes

October 18, 2011 | By Duchateaux.

If you have a Shared Remote Repository instead of directly Remove  Extra Commits you should provide to Revert them.
To Revert back the Latest Commit you perform:

git revert HEAD

This practically consist in Making a Commit with Opposite Effects with Respect to the Latest one.
To Revert the Next-to-Latest you execute:

git revert HEAD^

After your Commits History will be just leaved Untouched and so it will remain Easy to Communicate the Changes to your Remote by a Canonical:

git push origin master

If you don’t have a Remote Origin or you are the Only one to Push into the Remote you can proceed also to Removing your Commits with a Reset.
If you want directly to Delete/Remove/Destroy the Latest Commit perform:

git reset --hard HEAD^

If you want directly to Delete/Remove/Destroy the Latest Two Commits perform:

git reset --hard HEAD^^

If you want directly to Delete/Remove/Destroy the Latest Three Commits perform:

git reset --hard HEAD^^^

Be careful because you will Loose all data contained in the Commits…
After on your Remote Not Shared Repository you can Fix Commits History simply with a Force Flagged Push like :

git push -f origin master

QuickChic Theme • Powered by WordPress