Skip to content

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: Resolving Merge Conflicts Like a Pro

Git Conflicts Repeat in the Same Areas

Git: Switching Branches Without Committing Half-Done Work

Post Views: 3

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 *

October 2026
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  
« Sep    

Most Viewed Posts

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

Recent Posts

  • CSS: Fix a prefers-color-scheme Media Query That Gets Silently Overridden by a Browser Extension’s Forced Dark Mode
  • Git: Fix a Merge Commit That Silently Drops a File Because Both Branches Deleted It Differently
  • HTML5: Fix a Native Lazy-Loading Image That Never Loads Because It Sits Inside a Hidden Tab Until the User Clicks It
  • The AI Prompt That Traces a Null Reference Exception Back to the Exact Line That First Produced the Null
  • The AI Prompt That Turns a Gym Membership Contract’s Fine Print Into a Plain-English List of Cancellation Steps
  • Photoshop: Fix a Color Profile Mismatch That Makes Printed Output Look Nothing Like What You Saw On Screen
  • WordPress: Fix Search Results That Return Pages From a Theme You Deactivated Months Ago
  • Visual Studio: Fix a Test Project That Builds Fine Alone but Fails to Discover Any Tests After a NuGet Restore
  • ASP.NET Core: Fix a File Upload That Times Out on Slow Connections Only Because Kestrel’s Minimum Data Rate Feature Kicked In
  • JavaScript: Fix an Array Destructuring Default Value That Silently Never Applies Because null Was Passed Instead of Undefined

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (973)
  • How to make theater mode the default for Youtube (950)
  • How to add default value for Entity Framework migrations for DateTime and Bool (938)
  • Get the First and Last Word from a String or Sentence in SQL (847)
  • How to select distinct rows in a datatable in C# (836)

Recent Posts

  • CSS: Fix a prefers-color-scheme Media Query That Gets Silently Overridden by a Browser Extension’s Forced Dark Mode
  • Git: Fix a Merge Commit That Silently Drops a File Because Both Branches Deleted It Differently
  • HTML5: Fix a Native Lazy-Loading Image That Never Loads Because It Sits Inside a Hidden Tab Until the User Clicks It
  • The AI Prompt That Traces a Null Reference Exception Back to the Exact Line That First Produced the Null
  • The AI Prompt That Turns a Gym Membership Contract’s Fine Print Into a Plain-English List of Cancellation Steps

Social

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