• Skip to main content
  • Skip to after header navigation
  • Skip to site footer

Free-Mail

  • Events
  • Images
    • Instagram Goodness
  • Music
  • News
  • Software

Recover from an unsuccessful git rebase with the git reflog command

Recover from an unsuccessful git rebase with the git reflog command: Recover from an unsuccessful git rebase with the git reflog command agantony Mon, 01/16/2023 – 03:00

The git rebase command allows you to adjust the history of your Git repository. It’s a useful feature, but of course, mistakes can be made. As is usually the case with Git, you can repair your error and restore your repository to a former state. To recover from an unsuccessful rebase, use the git reflog command.

Git reflog

Suppose you perform this interactive rebase:

 $   git rebase -i HEAD~20

In this context, ~20 means to rebase the last 20 commits.

Unfortunately, in this imaginary scenario, you mistakenly squashed or dropped some commits you didn’t want to lose. You’ve already completed the rebase, but this is Git, so of course, you can recover your lost commits.

Review your history with reflog

 Run the git reflog command to collect data and view a history of your interactions with your repository. This is an example for my demonstration repository, however, the result will vary depending on your actual repository:

 $   git reflog 222967b (HEAD -> main) HEAD@{0}: rebase (finish): returning to refs/heads/main 222967b (HEAD -> main) HEAD@{1}: rebase (squash): My big rebase c388f0c HEAD@{2}: rebase (squash): # This is a combination of 20 commits 56ee04d HEAD@{3}: rebase (start): checkout HEAD~20 0a0f875 HEAD@{4}: commit: An old good commit [...]

Find the last good commit

In this example, HEAD@{3} represents the start of your rebase. You can tell because its description is rebase (start).

The commit just under it, 0a0f875 HEAD@{4}, is the tip of your Git branch before you executed your incorrect rebase. Depending on how old and active your repository is, there are likely more lines below this one, but assume this is the commit you want to restore.

More on Git
What is Git?
Git cheat sheet
Markdown cheat sheet
New Git articles

Restore the commit

To recover the commit you accidentally squashed and all of its parent commits, including those accidentally squashed or dropped, use git checkout. In this example, HEAD@{4} is the commit you need to restore, so that’s the one to check out:

 $   git checkout HEAD@{4}

With your good commit restored, you can create a new branch using git checkout -b as usual. Replace with your desired branch name, such as test-branch.

Git version control

Git’s purpose is to track versions, and its default setting is usually to preserve as much data about your work as feasible. Learning to use new Git commands makes many of its most powerful features available and safeguards your work.

The git rebase command allows you to adjust the history of your Git repository. It’s a useful feature, but of course, mistakes can be made. Use the git reflog command to recover.

Woman sitting in front of her laptop
Image by:

kris krüg

Git

What to read next
Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.
Register or Login to post a comment.

: Opensource.com agantony

Supporting Open Source.

Have you tried: Sailing in Africa ?

Share this:

  • Share on Facebook (Opens in new window) Facebook
  • Share on X (Opens in new window) X
  • Share on Pinterest (Opens in new window) Pinterest
  • Email a link to a friend (Opens in new window) Email
  • More
  • Share on Tumblr (Opens in new window) Tumblr
  • Print (Opens in new window) Print
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Reddit (Opens in new window) Reddit
Published on 16 January 2023 by Alan Category: SoftwareTag: command, From, rebase, recover, reflog, unsuccessful

Flutterwave wurde bei den Euromoney Transaction Banking Awards 2026 als „Afrikas bester Anbieter von Zahlungsinfrastruktur” ausgezeichnet

SAN FRANCISCO und LAGOS, Nigeria, 6. November 2026 /PRNewswire/ — Flutterwave, Afrikas …

Read moreFlutterwave wurde bei den Euromoney Transaction Banking Awards 2026 als „Afrikas bester Anbieter von Zahlungsinfrastruktur” ausgezeichnet

Trending Now: Tsunami

These are the latest trending searches on Google right now: Tsunami: : Daily Search Trends Have you …

Read moreTrending Now: Tsunami

Built E-HCS-BLK Small Hoodie Camera Case – Black

[wpramazon asin=”B00171VVNG” keyword=”Camera”]

Read moreBuilt E-HCS-BLK Small Hoodie Camera Case – Black

About Alan

Previous Post:abet
Next Post:Why food is such a powerful symbol in political protest

Reach Trust

Reach Trust is a holding trust for a number of companies within the Stratlec Group.

Copyright © 2026 · Free-Mail · All Rights Reserved · Powered by Straton Electrical

Back to top