How to undo a rebase in Git

Undoing a problematic rebase is crucial when Git operations go wrong and you need to restore your previous commit history safely. As the creator of CoreUI with over 25 years of development experience managing Git repositories since the early 2000s, I’ve had to undo rebases numerous times when conflicts became too complex or the rebase result wasn’t what was intended. The most reliable approach is using git reflog to find the commit before the rebase and git reset --hard to restore that state. This method provides a complete recovery mechanism that restores your branch to exactly how it was before the rebase operation.

Use git reflog to find the commit before rebase and git reset --hard to restore your previous state.

# View the reflog to find the commit before rebase
git reflog

# Reset to the commit before rebase (replace HEAD@{1} with your specific entry)
git reset --hard HEAD@{1}

# Alternative: reset to a specific commit SHA
git reset --hard abc1234

Git’s reflog keeps a history of all HEAD movements, including rebase operations. Use git reflog to see timestamped entries showing where HEAD pointed before the rebase. Look for entries like “rebase (start)” to identify the commit before your rebase began. Once you find the correct entry (usually HEAD@{1} for the most recent operation), use git reset --hard with that reference to completely restore your branch state. This discards all rebase changes and returns you to the exact state before the rebase started.

Best Practice Note:

This is the recovery method we use in CoreUI development when rebases become problematic or produce unexpected results. The reflog is local to your repository and expires after 90 days by default, so this method only works for recent operations and won’t affect commits already pushed to remote repositories.


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 loop through a 2D array in JavaScript
How to loop through a 2D array in JavaScript

How to check if an array is empty in JavaScript?
How to check if an array is empty in JavaScript?

How to get element ID in JavaScript
How to get element ID in JavaScript

How to Open All Links in New Tab Using JavaScript
How to Open All Links in New Tab Using JavaScript

Answers by CoreUI Core Team