How to reset a commit in Git

Resetting commits is crucial for cleaning up local repository history before sharing changes, allowing you to reorganize commits and remove unwanted changes. As the creator of CoreUI, a widely used open-source UI library, I’ve used git reset extensively for local history cleanup over 25 years of development. From my expertise, the most versatile approach is using git reset with different modes depending on whether you want to preserve or discard changes. This provides precise control over how commits are undone and what happens to the affected files.

Use git reset with different modes to control how commits are undone.

git reset --soft HEAD~1
git reset --mixed HEAD~1
git reset --hard HEAD~1

Here --soft moves HEAD back one commit but keeps changes staged, --mixed (default) unstages changes but keeps them in working directory, and --hard completely discards all changes. The HEAD~1 syntax refers to the commit before the current HEAD. Choose the mode based on whether you want to preserve the changes for recommitting.

Best Practice Note:

This is the same reset strategy we use in CoreUI development for local commit cleanup before pushing. Never use git reset on commits that have been pushed to shared repositories, as it rewrites history and can cause conflicts for other developers.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author