One data grid for JavaScript, React, Vue & Angular. Sorting, filtering, virtualization, pinning, and CSV export included. Early access $199 $349 → [Get it now]

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. 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

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.
How to conditionally add attributes to React components
How to conditionally add attributes to React components

How to force a React component to re-render
How to force a React component to re-render

What are the three dots `...` in JavaScript do?
What are the three dots `...` in JavaScript do?

How to replace all occurrences of a string in JavaScript?
How to replace all occurrences of a string in JavaScript?

Answers by CoreUI Core Team