If you wish to rewind the master branch of the repository to a previous pushed commit, simply run this command — of course, with the appropriate commit hash:

git reset --hard a0b1c2d3e4f5g6h7i8j9k0l1m2n3o4p5q6r7s8t9
git push --force

This may have unintended consequences if, for instance, there are collaborators on your repository. But, I am sure you know what you're doing 😉

Answer from GirkovArpa 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 do I undo the last commit without losing changes?
just committed but realized I need to edit some files before finalizing. How can I undo the last commit but keep my changes in the files? More on github.com
🌐 github.com
3
2
Undoing last commit
You should use git revert in this situation. It will undo the changes made by the faulty commit. Then push the newly created commit to remote. See https://git-scm.com/docs/git-revert for more info. More on reddit.com
🌐 r/git
12
6
January 7, 2021
Made a Mistake commit to master and it isn't going away!
Hi there! Well, it sounds like you made a commit that included a photo that is now a part of your commit history. When you created new branches after that (remember a branch in Git is just a fancy label that points to a commit) the commit with the photo would still be in that new branch history, since the new branch gets created at the current HEAD position. And like you mentioned, the `git revert` command just creates a new commit that undoes the changes in a previous commit, so that won't remove the photo commit from the history either, it will just create a new commit that deletes the file. It sounds like you have a couple of options depending on what you need to do: Use the `git reset` command to reset back to the commit _before_ you committed the photo Use the `git rebase` command to drop the commit with the photo If you only have a few commits and this is a test project, you could always just start over :D One last suggestion, if you want to try it, there is free Git simulation tool called Git-Sim which you can use to get a visual picture of what Git will do in your repo before running a command. It might help you better understand what is going on before running Git commands and getting into sticky situations. Here is the link if you want to check it out: https://github.com/initialcommit-com/git-sim More on reddit.com
🌐 r/git
20
0
June 25, 2024
🌐
GitHub
docs.github.com › en › desktop › managing-commits › undoing-a-commit-in-github-desktop
Undoing a commit in GitHub Desktop - GitHub Docs
If you want to edit your most recent ... GitHub Desktop. In the left sidebar, ensure you are on the Changes tab. At the bottom of the sidebar, click Undo....
🌐
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.
🌐
GitHub
github.com › orgs › community › discussions › 183621
undo the last commit · community · Discussion #183621
You can use git reset with the --soft or --mixed option to undo the last commit while keeping your changes.
Find elsewhere
🌐
Git Tower
git-tower.com › learn › git faq › how to undo, revert, or delete a git commit
How to Undo, Revert, or Delete a Git Commit | Learn Version Control with Git
If you'd prefer to unstage the changes but keep them in your working directory, omit the flag (the default is --mixed): ... In case you're using the Tower Git client, you can simply hit CMD+Z (or CTRL+Z on Windows) to undo the last commit:
Published   5 days ago
🌐
Augustana University
lovelace.augustana.edu › q2a › index.php › 7249 › how-can-i-undo-the-latest-3-commit-in-github
How can I undo the latest 3 commit in GitHub - Augustana CSC Q&A
Hi yall, I'm finishing my Step 7, adding a new choice of color in the ComboBox, I'm the ... know how to redo some of my latest commits. Thank you
🌐
SheCanCode
shecancode.io › home › news & articles › how to undo a commit in github
How to undo a commit in GitHub - SheCanCode
May 27, 2025 - A great hack is to add a number to the end of `~` to undo multiple commits. For example, to undo the last 2 commits – run git reset –soft HEAD~2.
🌐
GitHub
gist.github.com › gunjanpatel › 18f9e4d1eb609597c50c2118e416e6a6
Git HowTo: revert a commit already pushed to a remote repository · GitHub
Sometimes you may want to undo a whole commit with all changes. Instead of going through all the changes manually, you can simply tell git to revert a commit, which does not even have to be the last one. Reverting a commit means to create a new commit that undoes all changes that were made ...
🌐
CloudBees
cloudbees.com › blog › git-undo-commit
How to Undo Changes in Git with Git Undo Commit
November 25, 2020 - Before running git command --amend, remember to first stage your new changes with git add. Close your text editor after typing in the new commit message. When you come back to your terminal, you'll see something like this: ... The three undo ...
🌐
GitHub
github.blog › home › open source › how to undo (almost) anything with git
How to undo (almost) anything with Git - The GitHub Blog
July 23, 2024 - Undo with: git reset <last good SHA> or git reset --hard <last good SHA> What’s happening: git reset rewinds your repository’s history all the way back to the specified SHA. It’s as if those commits never happened.
🌐
Learn Git Branching
learngitbranching.js.org
Learn Git Branching
An interactive Git visualization tool to educate and challenge!
🌐
freeCodeCamp
freecodecamp.org › news › git-revert-commit-how-to-undo-the-last-commit
Git Revert Commit – How to Undo the Last Commit
August 31, 2021 - If you want to reset to the last commit and also remove all unstaged changes, you can use the --hard option: ... This will undo the latest commit, but also any uncommitted changes.
🌐
JanBask Training
janbasktraining.com › community › devops › how-does-the-git-undo-last-commit-method-work
How does the git undo last commit method work?
November 7, 2023 - Be the expert of deployment for your company. Learn the DevOps skills with the latest DevOps Training. Master the concepts of facilitated delivery and conveyance through DevOps Online Training.
🌐
Kilo
kilo.ai › docs › code-with-ai › platforms › cli
Kilo Code CLI: Run the AI Coding Agent from Your Terminal
The TUI gives Ctrl+Z to input undo on Windows because native Windows terminals do not support POSIX terminal suspend. On Windows, input_undo defaults to ctrl+z,ctrl+-,super+z and terminal_suspend is disabled.
🌐
W3Schools
w3schools.com › git › git_staging_environment.asp
Git Staging Environment
Forgot to stage a file? Just run git add <file> again before you commit.
🌐
ChatGPT Learn
developers.openai.com › codex › cli › slash-commands
Developer commands | ChatGPT Learn
May 7, 2026 - Run a non-interactive review of uncommitted changes, a base branch diff, a commit, or custom review instructions.
🌐
Commands.dev
commands.dev › workflows › undo_most_recent_git_commit
Undo most recent git commit
Undos the last git commit while ... terminal with AI and your dev team's knowledge built-in. Download Now · Command · git reset HEAD~ Tags · git · Edit in GitHubCopy URL...
🌐
OpenReplay
blog.openreplay.com › openreplay blog › undoing git commits after push: safely revert changes on remote repositories
Undoing Git Commits After Push: Safely Revert Changes on Remote Repositories
November 30, 2024 - # Make necessary changes git add . git commit --amend · When you need to undo commits that have already been pushed to a remote repository, you should use git revert to create a new commit that undoes the changes.