Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
Git

Git: Recover a Commit Lost After an Interactive Rebase Accidentally Drops It

- 03.10.26 - ErcanOPAK

🔀 The Commit That Vanished From an Interactive Rebase Without a Trace

An interactive rebase lets you reorder, squash, reword, and drop commits by editing a simple todo list before Git replays them one by one – which is exactly what makes it easy to delete the wrong line, or change pick to drop on a commit you actually meant to keep. Once the rebase finishes, that commit is gone from the branch’s history as if it never happened, with no warning and no undo prompt, even though the commit object itself is still sitting intact in Git’s object database for a while yet.

🔎 The Problem

$ git rebase -i HEAD~5
# In the editor, you meant to drop a different line but accidentally
# changed "pick a1b2c3d Add refund calculation" to "drop a1b2c3d ..."

$ git log --oneline
# a1b2c3d (the refund calculation commit) is simply gone - no error,
# no warning, the rebase completed successfully.

# The commit still exists; reflog remembers where HEAD pointed before
# the rebase ran:
$ git reflog
f9e8d7c HEAD@{0}: rebase (finish): returning to refs/heads/feature
...
c4d5e6f HEAD@{5}: rebase (start): checkout HEAD~5
a9b8c7d HEAD@{6}: commit: Add refund calculation   <- the commit
                                                        right before
                                                        the rebase started

✅ Fix: Use the Reflog to Find and Cherry-Pick the Dropped Commit Back

  • Run git reflog immediately – it records every position HEAD has pointed to, including right before the interactive rebase started, so you can find the commit’s hash even though it no longer appears in git log.
  • Once you have the dropped commit’s hash, run git cherry-pick with that hash on your current branch to reapply it cleanly, rather than trying to redo the entire rebase from scratch.
  • Act quickly: reflog entries are not permanent and eventually expire (90 days by default for reachable commits, much sooner for ones Git considers already unreachable), after which the commit becomes genuinely unrecoverable through normal means.

⚠️ Why This Is Easy to Miss

  • The rebase itself reports success with no errors, and the resulting history looks clean and intentional – there’s no diff, no warning dialog, nothing that distinguishes an accidental drop from a deliberate one.
  • The missing commit is often only noticed much later, when a feature it implemented turns out to be missing in testing or production, by which point it’s easy to assume the work was never committed in the first place rather than lost in a rebase.

Git doesn’t forget a commit the moment you drop it – it just stops showing it to you, and the reflog is where it keeps the receipt.

— Version Control Tip

Related posts:

Git: Use Interactive Rebase to Clean Up Commit History Before Merge

Git: Use Interactive Rebase to Clean Up Commit History Before Merge

Git: Use .gitignore to Exclude Files

Git: Use .gitignore to Exclude Files

Git: Fix a .gitattributes merge=union Setting That Silently Keeps Both Sides of Every Conflict

Git: Fix a .gitattributes merge=union Setting That Silently Keeps Both Sides of Every Conflict

Views: 13

Post navigation

Windows 11: Fix a Microphone Other People Can’t Hear Even Though Your Own Input Meter Looks Fine
Docker: Fix an ENTRYPOINT and CMD Combination That Silently Ignores Arguments Passed at docker run

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,068)
  • Get the User Name and Domain Name from an Email Address in SQL (990)
  • How to add default value for Entity Framework migrations for DateTime and Bool (986)
  • Get the First and Last Word from a String or Sentence in SQL (865)
  • How to select distinct rows in a datatable in C# (859)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (661)
  • Add Constraint to SQL Table to ensure email contains @ (619)
  • Average of all values in a column that are not zero in SQL (577)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (553)
  • Find numbers with more than two decimal places in SQL (481)

Recent Posts

  • Network Speed Monitor Windows Application v2.5.1
  • Ağ Hızı İzleyici Windows Uygulaması v2.5.1
  • How to make theater mode the default for Youtube
  • The AI Prompt That Audits a Function for Thread-Safety Gaps
  • Ajax: Fix a Fetch Request Caching a Response Despite No-Store
  • WordPress: Fix a Navigation Block Losing Submenu Items After Sync
  • Visual Studio: Fix CodeLens Reference Counts Stuck at Stale Numbers
  • C#: Fix a UTF-8 String Literal Behaving Differently in a Switch
  • Photoshop: Fix a Liquify Mesh Snapping Back on a Smart Object
  • The AI Prompt That Turns a Crash Dump Into a Short Repro Script

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,068)
  • Get the User Name and Domain Name from an Email Address in SQL (990)
  • How to add default value for Entity Framework migrations for DateTime and Bool (986)
  • Get the First and Last Word from a String or Sentence in SQL (865)
  • How to select distinct rows in a datatable in C# (859)

Recent Posts

  • Network Speed Monitor Windows Application v2.5.1
  • Ağ Hızı İzleyici Windows Uygulaması v2.5.1
  • How to make theater mode the default for Youtube
  • The AI Prompt That Audits a Function for Thread-Safety Gaps
  • Ajax: Fix a Fetch Request Caching a Response Despite No-Store

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com