Branches and rebase

Undo a git rebase mistake: reflog, reset or revert

Undo a git rebase: find the old branch tip in git reflog, reset your commits to it, or revert the changes if the rebase was already pushed.

On this page

Can you undo a git rebase once it is done?

Yes. The rebase rewrote your branch history with new commits, but the old ones stay in your local repository and the reflog remembers them. If you have not pushed yet, find the commit your branch pointed to before, then reset the branch to it:

git reflog
git reset --hard <commit-before-the-rebase>

If the branch is already on the remote, use git revert instead, covered further down.

The examples use a throwaway repository, orbit-api, where feature/export held two commits on an old main. You ran git rebase main, picked the wrong base or resolved a conflict in a hurry, and want the branch back. The outputs come from Git 2.54, and your IDs will differ.

Find the commit from before the rebase in the git reflog

The reflog is where you recover lost commits. It’s a local history of each move of a branch tip or another reference. HEAD@{2} means “where HEAD used to be two moves ago”, in the words of the reflog documentation.

git reflog -5
7fc0b2a HEAD@{0}: rebase (finish): returning to refs/heads/feature/export
7fc0b2a HEAD@{1}: rebase (pick): feat: stream large exports
c32c9e7 HEAD@{2}: rebase (pick): feat: add CSV export endpoint
65e4954 HEAD@{3}: rebase (start): checkout main
8c88ff0 HEAD@{4}: checkout: moving from main to feature/export

The top four lines are the rebase itself. The line just below rebase (start) is your branch before it began: 8c88ff0. Check it with git log before you touch anything:

git log --oneline -3 8c88ff0
8c88ff0 feat: stream large exports
a2ef4c5 feat: add CSV export endpoint
beae563 chore: init orbit-api

Both commits sit on the old base, without feat: add users route from main. That is the commit history you want back.

Reflog entries expire: by default after 90 days, or 30 days when their commit is no longer reachable from the current tip. The old commits a rebase leaves behind are in the second case. The reflog is also local, so another clone has its own.

Reset to that commit: what git reset –hard does to your changes

This command moves the current branch to the commit you give it. Per the git-reset documentation, it also overwrites your files with that commit’s version, and may overwrite untracked files. Run git status first, and commit or git stash the work you want to keep.

git status -sb
git reset --hard 8c88ff0
## feature/export
HEAD is now at 8c88ff0 feat: stream large exports

The history of feature/export is back on its old base:

git log --oneline --graph --decorate --all
* 65e4954 (main) feat: add users route
| * 8c88ff0 (HEAD -> feature/export) feat: stream large exports
| * a2ef4c5 feat: add CSV export endpoint
|/
* beae563 chore: init orbit-api

git reset --soft is not the same undo. It moves the branch but leaves your working tree and the staging area unchanged, so your files keep the rebased version.

Right after the rebase, git reset --hard ORIG_HEAD is a shortcut, since Git points ORIG_HEAD at the old tip when the rebase starts. But any reset moves it, even one run during the rebase. After the reset above, it names 7fc0b2a, the rebased tip.

feature/export@{1}, the previous position of the branch, is the safer form right after a rebase.

Undo a rebase you already pushed: git revert, not reset

Once the rebased branch is on GitHub or another remote, someone may have fetched it. A reset and a force push would rewrite that shared history a second time, so avoid them on a branch other people use.

git revert records new commits that undo the changes of the commits you name, and leaves the existing history as it is:

git revert <faulty-commit>

It accepts one or more commits and, per the git-revert documentation, requires a clean working tree. It cancels the effect of specific commits, such as a bad conflict resolution, but it does not bring back the graph you had before. If the branch is yours alone, the reset above still works, followed by a force push.

Abort a rebase that is still running on your branch

If the rebase stopped on a conflict, there is nothing to dig out of the reflog yet. git rebase --abort stops it and puts you back on the original branch. To keep going instead, resolve the conflicts, stage the files with git add, then run git rebase --continue.

The guide to interactive rebase walks through both on a real conflict.

Get your branch back in GitMini: undo and the reflog panel

GitMini, a desktop Git client, keeps track of the rebases you run in the app. Right after one, a toast offers Undo for ten seconds. The Undo button in the toolbar (Cmd/Ctrl+Z) does the same later, as long as the rebase is the last operation the app can undo: after a confirmation, the branch returns to its old tip. The reflog panel lists where HEAD has been, with Create a branch here… on each entry. Every write goes through the Git CLI, and GitMini needs Git 2.30 or later in your PATH.

Sources

  • Git documentation: git-reflog, consulted on November 8, 2026.
  • Git documentation: git-rebase, consulted on November 8, 2026.
  • Git documentation: git-reset, consulted on November 8, 2026.
  • Git documentation: git-revert, consulted on November 8, 2026.
  • GitMini product README and app (version 0.3.1), consulted on November 10, 2026.