Undo a GitHub commit with ease. Follow our step-by-step guide to view history, use git revert/reset, amend commits, and update your repository safely.
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: View Your Commit History
Run the following command to see a concise list of recent commits:
git log --oneline
Step 2: Undo a Specific Commit Using git revert
git revert
command creates a new commit that reverses the changes introduced by a given commit, preserving history.git log --oneline
.Use git revert
like this:
git revert
Step 3: Undo the Last Commit Locally Using git reset
git reset --soft HEAD~1
git reset --mixed HEAD~1
git reset --hard HEAD~1
Step 4: Amend the Last Commit Instead of Undoing
--amend
.
git add . # Stage any new changes
git commit --amend -m "New message"
Step 5: Push Your Changes to GitHub
git revert
or git commit --amend
, a normal git push
is sufficient:
git push origin main
git reset
or --amend
on a commit that was already pushed, you must force-push:
git push --force origin main
Step 6: Revert a Pull Request on GitHub Website
Additional Tips
git reflog
to recover commits after a hard reset or other history edits.When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.