Learn how to rollback changes in GitHub step-by-step—from checking status and discarding unstaged changes to reverting commits and force pushing updates.
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: Check Your Current Git Status
git status
to see which files are modified, staged, or untracked.
git status
Step 2: Discard Unstaged Local Changes
git checkout
(Git 2.23+ uses git restore
).
// For older Git versions
git checkout -- path/to/file
// Or with Git 2.23+
git restore path/to/file
Step 3: Unstage Staged Changes
git add
) but want to remove them from staging without deleting your edits, use git reset
.
git reset HEAD path/to/file
Step 4: Revert a Commit Without Changing History
git revert
if the commit is already pushed or merged and you want to create a new commit that undoes the changes.
git revert <commit-hash>
# Follow prompts to edit commit message, then save and exit.
Step 5: Reset to a Previous Commit (Local History Rewrite)
git reset --hard
.
git reset --hard <commit-hash>
Step 6: Force Push to Remote (If You Rewrote Public History)
git reset --hard
on a branch that others pull from, you must force-push to overwrite the remote history.
git push --force origin branch-name
Step 7: Revert a Merged Pull Request via GitHub UI
Step 8: Verify Your Rollback
git log
or view the commit history on GitHub to confirm the rollback or revert commits are present.git status
again to ensure your working directory is clean.
git log --oneline
git status
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.