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 revert a commit in Git

Reverting commits safely is essential for undoing problematic changes in shared repositories without disrupting other developers’ work or rewriting project history. As the creator of CoreUI, a widely used open-source UI library, I’ve safely reverted countless commits in production repositories. From my expertise, the safest approach is using git revert, which creates a new commit that undoes the changes from a previous commit. This maintains the integrity of the project history while effectively canceling out unwanted changes.

Use git revert to create a new commit that undoes changes from a previous commit.

git revert abc123f
git revert HEAD~2

Here the first command reverts the specific commit with hash abc123f, creating a new commit that undoes those changes. The second command reverts the commit that was 2 commits before the current HEAD. Git automatically creates a commit message describing the revert, but you can edit it if needed. This approach is safe for shared repositories because it doesn’t rewrite history.

Best Practice Note:

This is the same safe revert strategy we use in CoreUI project maintenance for production code corrections. Use git revert instead of git reset for commits that have been pushed to shared repositories, as it preserves history and prevents 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 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?

How to remove a property from an object in Javascript
How to remove a property from an object in Javascript

Answers by CoreUI Core Team