If your excess commits are only visible to you, you can just do git reset --hard origin/<branch_name> to move back to where the origin is. This will reset the state of the repository to the previous commit, and it will discard all local changes.

Doing a git revert makes new commits to remove old commits in a way that keeps everyone's history sane.

Answer from Ben Jackson on Stack Overflow
🌐
Reddit
reddit.com › r/git › how can i completely delete commits from both local and remote?
r/git on Reddit: How can I completely delete commits from both local and remote?
May 11, 2020 -

Hi there –

I've made a complete mess of my repo. Three branches are now in an unreliable state.

Unfortunately, much of the mess is already on GitHub.

I'd like to completely delete all commits that were made after a certain point, so that I can start over with a clean slate.

How can I do this, in a way that will also delete the problematic commits from GitHub?

Unfortunately, I'm not a very proficient Git user – so anything about rebasing, reflogs, etc. is going to lose me very quickly. Please, speak slowly and use small words :)

Thanks for any suggestions.

ETA: I found this StackOverflow answer, which recommends doing git reset --hard <last_working_commit_id> to delete the bad commits, and then using git push --force to delete them from GitHub. This sounds easy, but is there anything I should consider before using this technique?

🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-delete-local-commit-in-git
How to Delete Local Commit in Git? - GeeksforGeeks
July 23, 2025 - Find the commit hash you want to revert to using git reflog: ... Keeps the changes in your working directory and staging area. ... Discards all changes and resets your working directory and staging area. ... Rewrites remote history, should be used with caution. By following these steps, you can effectively manage and delete local commits in your Git repository.
🌐
Nick Janetakis
nickjanetakis.com › blog › undo-remove-or-revert-specific-git-commits
Undo, Remove or Revert Specific Git Commits — Nick Janetakis
July 1, 2025 - You can do an interactive rebase and drop the commit. I’ve written about using interactive rebase to change commits in the past, this will be similar. ... Like the first example you can replace HEAD~N with the GIT_SHA^. If you want to delete the oldest commit you can use --root instead of HEAD~N / GIT_SHA^.
🌐
Reddit
reddit.com › r/git › is there a way to remove all local commits while keeping the changes?
r/git on Reddit: Is there a way to remove all local commits while keeping the changes?
February 17, 2022 -

I would like to organize my PR after my feature is done by removing all of my 'work in progress'-commits and creating new commits that group files to improve the readability of my PR.
I have tried using git reset, but that only unstages changes that have been added using git add . & all files that are already committed seem to be out of reach.

🌐
GitHub
gist.github.com › silent1mezzo › 1670623
On undoing, fixing, or removing commits in git · GitHub
Those can be deleted with git clean -nd git clean -ndX respectively, or git clean -ndx for both at once. Well, actually those command do not delete the files. They show what files will be deleted.
Find elsewhere
🌐
Aviator
aviator.co › home › blog › how to git undo commit: methods and best practices
How to Git Undo Commit: Methods and Best Practices - Aviator Blog
February 10, 2025 - Made a mistake in Git? No worries! This guide covers git reset, git revert, and git reflog to undo commits safely, whether they’re local or already pushed. Learn when to keep, unstage, or discard changes and how to recover lost commits.
🌐
Alexstrick
alexstrick.com › posts › 2023-04-28-removing-git-commits.html
How to remove a commit (or two) from your git branch – Alex Strick van Linschoten
April 28, 2023 - Use git rebase -i (interactive rebase) to remove the commit. This command will open an editor where you can manipulate the commit history. Use the commit hash that’s one before the one you want to remove: ... In the editor that opens, you ...
🌐
Medium
medium.com › @sivaraaj › how-to-undo-the-most-recent-local-commits-in-git-7892fd717964
How to Undo the Most Recent Local Commits in Git ? | by Sivaraj Ramasamy | Medium
February 18, 2024 - $ git log --oneline a1b2c3d (HEAD -> main) Add new feature e4f5g6h Initial commit $ git revert a1b2c3d [main 7h8i9j0] Revert "Add new feature" 1 file changed, 1 insertion(+), 1 deletion(-) $ git log --oneline 7h8i9j0 (HEAD -> main) Revert "Add new feature" a1b2c3d Add new feature e4f5g6h Initial commit
🌐
Xebia
xebia.com › home › blog › how to delete git commit history – a step-by-step guide
How to Delete Git Commit History – A Step-by-Step Guide
1 month ago - Delete the local default branch that still contains the full commit history with git branch -D main, rename the temporary branch to become the new default with git branch -m main, and force update the remote repository with git push --force ...
🌐
Better Stack
betterstack.com › community › questions › how-to-remove-git-commit-not-pushed
Remove a Git Commit Which Has Not Been Pushed | Better Stack Community
In the editor that opens, find the commit you want to remove. Delete the entire line for that commit or change pick to drop in front of the commit hash. ... Save and close the editor to apply the rebase.
🌐
Graphite
graphite.com › guides › how-to-delete-a-git-commit
How to delete a git commit
Deleting a commit from a remote repository can be dangerous, as it always requires rewriting the Git history of the target branch. Proceed with caution and communicate with your other collaborators prior to running any destructive commands. If you've pushed a commit to a remote repository and want to remove it: ... This command deletes the most recent commit from your local repository, and discards the changes from that commit.
🌐
GitLab
docs.gitlab.com › topics › git › undo
Revert and undo changes | GitLab Docs
A branch of a merge request is a public branch and might be used by other developers. However, the project rules might require you to use git rebase to reduce the number of displayed commits on target branch after reviews are done. You can modify history by using git rebase -i. Use this command to modify, squash, and delete commits.
🌐
BelieveMy
believemy.com › en › r › how-to-delete-a-git-commit
How to delete a Git commit?
December 5, 2024 - Deleting a commit in Git is a common task, but one that needs to be performed with care, especially when working with other developers. You can choose between git reset to roll back the local history, git revert to cleanly undo a commit, or ...
🌐
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 ...
🌐
Instagram
instagram.com › popular › how-to-revert-local-git-commit
How To Revert Local Git Commit
April 1, 2026 - We cannot provide a description for this page right now
🌐
Python documentation
docs.python.org › 3 › library › sqlite3.html
sqlite3 — DB-API 2.0 interface for SQLite databases
Close the database connection. If autocommit is False, any pending transaction is implicitly rolled back. If autocommit is True or LEGACY_TRANSACTION_CONTROL, no implicit transaction control is executed.
🌐
Fork
git-fork.com
Fork - a fast and friendly git client for Mac and Windows
Edit, reorder and squash your commits using visual interactive rebase.
🌐
Reliable Penguin
blogs.reliablepenguin.com › home › undoing local git commits you haven’t pushed (safely)
Undoing local Git commits you haven’t pushed (safely) Undo Unpushed Git Commits Safely (Exact Commands)
October 10, 2025 - Made a few local commits and realized they aren’t quite right—and nothing’s been pushed yet? This guide shows exactly how to unwind safely. Choose to discard everything, keep your changes unstaged, or keep them staged for a clean recommit, with copy-pasteable git reset commands for each path.