git revert commits a reverse change, so from the history point of view you will have two unnecessary commits that cancel each other. The {commit#} in your case should be the ID of the commit that you want to undo (= the last one). This should work as long as there are no other commits on top of it, otherwise you might get conflicts which require more work.

If you don't have any other commits apart from the one you want to undo, there is also a better way - simply move the branch back to point to the last commit you want to keep (= one before last).

Something like this (I assume you are working on master, that you didn't do revert yet and that there are no other people involved):

git checkout -b tmp_branch master~1
git branch -f master tmp_branch
git checkout master
git branch -D tmp_branch
git push -f origin master

And voilà. If your master is protected in GitHub, you will have to unprotect it. You can repeat this to go further back (or just use ~2, ~3 etc.)

Answer from jurez on Stack Overflow
Discussions

revert to previous commit on github?
As a general rule, once you push your repository to a remote repository, your commits should be considered permanent. By resetting your repository to an earlier state, you made it impossible to push to the remote repository. You have a couple options: git push -f will override that rule and allow you to push. I don't recommend this option unless you're the only user of that remote repository. If other people have been pulling from that repository, you will very likely mess them up. You also might not have the necessary permissions to do this if this is someone else's repository. Go back to where you before you executed git reset --hard and do it right. You could execute these steps: commands: git branch foo (makes a placeholder to where you are now) git pull (get your local repository back in sync with the remote) git revert git push What git revert does is construct a whole new commit that un-does the one you want to get rid of. The old one remains in the git history and then there's a new commit that reverses it. There's no way to really get rid of the old one since it's there in the remote repository and in the repositories of anybody who's pulled from it. If what you want to do something more complicated than just reverting one commit, then there is where branch "foo" comes in: git branch foo (makes a placeholder to where you are now) git pull (get your local repository back in sync with the remote) git diff HEAD foo > /tmp/patch patch -p1 < /tmp/patch git commit -a git push If it's not obvious, what this does is construct a patch that will change all the files in your current branch to what they were in your "reverted" branch. Then you apply that patch and commit the changes. My notes on the subject: http://www.efalk.org/Docs/Git/merging.html Disclaimer: these are Unix commands. If you're on Windows, you're on your own here. More on reddit.com
🌐 r/git
3
0
January 17, 2025
how to go back to a state at a commit?
Copy the git sha of the commit you wanna go back to. Checkout that sha with git checkout. If it’s not too far back you could do a git reset head. Come to think of it you might be able to git restore to just restore everything to that sha. Anyhow after all that you would need to force push to overwrite the branch. Now that I answered your question let me ask the real question. Why not just fix the bug with a new commit? Why undo all the work you have already done? More on reddit.com
🌐 r/github
12
2
January 5, 2024
Made an error in reverting my git commit
Body hi All Hoping someone can help get me back to state where I want to get on this.... I accidentally reverted a commit that I did not want to revert using git revert Actually I just wanted to ge... More on github.com
🌐 github.com
3
1
git - Can I revert commits directly on GitHub? - Stack Overflow
It seems like you can do just about everything else directly on GitHub using the web interface, like edit and create and delete files, but I am unable to find a way to revert a commit, like you can... More on stackoverflow.com
🌐 stackoverflow.com
People also ask

Can I revert multiple commits in GitHub?
Yes, you can revert multiple commits in GitHub, but it must be done one at a time. Each revert action creates a new commit that undoes the changes of a specific previous commit, ensuring that the project history remains clear and organized.
🌐
thetechedvocate.org
thetechedvocate.org › home › how to revert commit in github
Thetechedvocate
How do I revert a commit directly on GitHub?
Open the commit page in GitHub and click Revert. GitHub creates a new branch and pull request containing the inverse commit.
🌐
devtoolbox.dedyn.io
devtoolbox.dedyn.io › home › blog › revert a commit on github
Revert a Commit on GitHub: Web UI + Git CLI (2026 Guide) | DevToolbox ...
Why is the GitHub Revert button missing?
The button may be unavailable if GitHub detects conflicts, the branch no longer exists, or the commit type cannot be auto-reverted. Use git revert from the command line in that case.
🌐
devtoolbox.dedyn.io
devtoolbox.dedyn.io › home › blog › revert a commit on github
Revert a Commit on GitHub: Web UI + Git CLI (2026 Guide) | DevToolbox ...
🌐
The Tech Edvocate
thetechedvocate.org › home › how to revert commit in github
Thetechedvocate
10 hours ago - To revert a commit on GitHub, navigate to your repository, find the commit you want to revert, and select the 'Revert' option. This action will generate a new commit that undoes the changes made by the selected commit, allowing you to maintain ...
🌐
TheServerSide
theserverside.com › tutorial › How-to-git-revert-a-commit-A-simple-undo-changes-example
How to revert a Git commit: A simple example | TheServerSide
The git revert command is a simple way to remove a bug introduced to the version control system at some point in the past, or back out of a feature enhancement that wasn't well-received by the client.
🌐
Reddit
reddit.com › r/git › revert to previous commit on github?
r/git on Reddit: revert to previous commit on github?
January 17, 2025 -

Hi, I would like to revert to a previous commit. I believe I did this correctly on my local repository using git reset --hard commit-hash. I would like to push this to github but of this results in

error: failed to push some refs to 'https://github.com/shmish/smartmark.git'
hint: Updates were rejected because the tip of your current branch is behind

I am the only working on this repository, so I am not worried about conflicts, I am trying to move back one commit.

Top answer
1 of 2
14
As a general rule, once you push your repository to a remote repository, your commits should be considered permanent. By resetting your repository to an earlier state, you made it impossible to push to the remote repository. You have a couple options: git push -f will override that rule and allow you to push. I don't recommend this option unless you're the only user of that remote repository. If other people have been pulling from that repository, you will very likely mess them up. You also might not have the necessary permissions to do this if this is someone else's repository. Go back to where you before you executed git reset --hard and do it right. You could execute these steps: commands: git branch foo (makes a placeholder to where you are now) git pull (get your local repository back in sync with the remote) git revert git push What git revert does is construct a whole new commit that un-does the one you want to get rid of. The old one remains in the git history and then there's a new commit that reverses it. There's no way to really get rid of the old one since it's there in the remote repository and in the repositories of anybody who's pulled from it. If what you want to do something more complicated than just reverting one commit, then there is where branch "foo" comes in: git branch foo (makes a placeholder to where you are now) git pull (get your local repository back in sync with the remote) git diff HEAD foo > /tmp/patch patch -p1 < /tmp/patch git commit -a git push If it's not obvious, what this does is construct a patch that will change all the files in your current branch to what they were in your "reverted" branch. Then you apply that patch and commit the changes. My notes on the subject: http://www.efalk.org/Docs/Git/merging.html Disclaimer: these are Unix commands. If you're on Windows, you're on your own here.
2 of 2
4
I am the only working on this repository, so I am not worried about conflicts In this case, a git reset … followed by a git push --force-with-lease is totally fine. (note: a simple push -f would also work, but you should get into the habit of using force-with-lease for later.
Find elsewhere
🌐
DevToolbox
devtoolbox.dedyn.io › home › blog › revert a commit on github
Revert a Commit on GitHub: Web UI + Git CLI (2026 Guide) | DevToolbox Blog
February 16, 2026 - Tip: Revert is safer than reset for pushed commits because it keeps history intact and avoids force-push recovery work for teammates. Use this when a single commit introduced a bug and you want a PR-based rollback from the web interface.
🌐
LightNode
go.lightnode.com › tech › rollback-commit-github
How to Rollback Commits in GitHub: A Complete Developer's Guide
July 24, 2025 - git revert abc123 -m "Rollback: Fix critical authentication bug introduced in abc123" Test Thoroughly: After rolling back commits, test the affected functionality to ensure everything works as expected. Update Related Issues: If the rollback relates to GitHub issues or pull requests, update them with the rollback information.
🌐
GitHub
gist.github.com › gunjanpatel › 18f9e4d1eb609597c50c2118e416e6a6
Git HowTo: revert a commit already pushed to a remote repository · GitHub
Reverting a commit means to create a new commit that undoes all changes that were made in the bad commit. Just like above, the bad commit remains there, but it no longer affects the the current master and any future commits on top of it.
🌐
Reddit
reddit.com › r/github › how to go back to a state at a commit?
r/github on Reddit: how to go back to a state at a commit?
January 5, 2024 -

I have GitHub Desktop and I have been making regular commits. Now a bug was introduced and I want to go back and get the whole project as it was in time at a previous commit.

How to do that is not entirely intuitive. How do you go back to a previous state of the entire project at the point of a single commit?

There are no local changes according to Github Desktop....

no changes

The commit that I want to go back to is the 3rd commit down on the left. I figure that (according to their instructions) I would revert the two latest commits and I'd be back where I want to be.

a simple plan

But Github protets and claims there are changes.....

only there aren't any changes

But, there aren't any changes.

WTF Github?

I'm not worried about the code......

I'm just irritated that a versioning system so widely used would be so poorly designed.

Top answer
1 of 3
4
Copy the git sha of the commit you wanna go back to. Checkout that sha with git checkout. If it’s not too far back you could do a git reset head. Come to think of it you might be able to git restore to just restore everything to that sha. Anyhow after all that you would need to force push to overwrite the branch. Now that I answered your question let me ask the real question. Why not just fix the bug with a new commit? Why undo all the work you have already done?
2 of 3
1
Sounds like you were just confused with terminology, which is entirely understandable. Git involves a lot of words that mean very specific things within the context of Git, but are more flexible in ordinary language. In this case, you thought "revert" would do what you wanted, but what that actually means is to permanently revert something going forward. You use it when you decide that some changes you made before are inappropriate and should be undone (and they were in a shared branch that you want to keep using, so you can't merely ignore the last few commits; you need the reversion to explicitly exist in history). What you really want is to "check out" an old commit. Think of it like checking out a book at your local library. You want to read it for a while, and then return to what you were doing before. This is a read-only operation in terms of version history; you're not modifying history by adding a new event to it the way that revision does. You're only browsing through history, observing what it looked like at various moments by modifying only your local working copy.
🌐
CloudBees
cloudbees.com › blog › git-revert-explained
Git Revert Explained: Safely Undoing Your Changes
November 29, 2021 - In a situation like this, instead of manually trying to locate the bug—which, of course, will take more time—you can undo just the commit that introduced the bug by using git revert.
🌐
GitKraken
gitkraken.com › home › learn › problems & solutions › how to revert a git commit
Git Revert Commit | Solutions to Git Problems
February 5, 2024 - Learn how to use Git revert to undo changes introduced in a specified commit or group of commits. See examples of Git revert commit in the terminal, GitKraken Client, & GitLens.
🌐
Git
git-scm.com › docs › git-revert
Git - git-revert Documentation
This requires your working tree to be clean (no modifications from the HEAD commit). Note: git revert is used to record some new commits to reverse the effect of some earlier commits (often only a faulty one). If you want to throw away all uncommitted changes in your working directory, you should see git-reset[1], particularly the --hard option.
🌐
GitHub
docs.github.com › en › desktop › managing-commits › resetting-to-a-commit-in-github-desktop
Resetting to a commit in GitHub Desktop - GitHub Docs
If you made a series of commits and want to fix a mistake you made prior to the most recent commit, you can use "reset to commit" in GitHub Desktop to reset the changes in those commits.
🌐
TMS Outsource
tms-outsource.com › home › how to revert to a previous commit in github
How to Revert to a Previous Commit in GitHub - TMS Outsource
December 14, 2025 - Reverting to a previous commit in GitHub is the process of undoing changes in your repository by either creating a new commit that cancels out unwanted modifications or resetting your branch pointer to an earlier state.
🌐
Linuxize
linuxize.com › home › git › how to revert a commit in git
How to Revert a Commit in Git | Linuxize
May 23, 2026 - To revert the “Fix navigation bug” commit, pass its hash to git revert: