Learn how to safely revert to a previous project version with Git. This guide covers commit checkout, branch creation, hard resets, and using git revert.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Step 1: Open Your Terminal or Command Prompt
Open the terminal (Linux/macOS) or Git Bash/Command Prompt (Windows) so you can run Git commands.
Step 2: Navigate to Your Local Repository
Use the cd command to move into the folder where your project is stored.
cd path/to/your/project
Step 3: View the Commit History
Run git log in a concise form to find the commit hash you want to revert to.
git log --oneline
Step 4: Check Out the Desired Commit Locally
This lets you inspect the project at that point in time without altering your current branch permanently.
git checkout COMMIT\_HASH
Replace COMMIT_HASH with the actual identifier (for example, a1b2c3d).
Step 5: Create a New Branch from the Old Commit (Optional but Safe)
If you want to preserve your current work, create a new branch at that commit first.
git checkout -b revert-to-old-version
Step 6: Hard Reset Your Main Branch to That Commit
If you prefer to move your existing branch (for example, main) back in time, switch back to it and reset it.
git checkout main
git reset --hard COMMIT\_HASH
Step 7: Push the Reverted State to GitHub
After resetting, update the remote branch. If you reset the main branch, you must force-push.
git push origin main --force
Step 8: Alternative Method—Use git revert to Create a New “Undo” Commit
Instead of rewriting history, you can generate a new commit that reverses one or more earlier commits. This is safer for shared branches.
git checkout main
git revert COMMIT\_HASH
git push origin main
Step 9: Verify the Reverted Version on GitHub
Go to your repository on GitHub and confirm that the files and commit history reflect the previous version you intended.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.