Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio

Bits of .NET

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

  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio
Git

Git: Fix a Rebase –onto Leaving Orphaned Commits Behind

- 29.11.26 - ErcanOPAK

🔀 Fix a Rebase –onto Leaving Orphaned Commits Behind

git rebase –onto newbase oldbase branch replays the commits unique to branch on top of newbase and moves the branch pointer to the result, but the original commits — the ones that existed before the rebase ran — don’t disappear. They simply stop being reachable from any branch, staying alive only through the reflog, which by default expires unreachable entries after 90 days. That’s expected, working-as-designed behavior, but it surprises people who check disk usage or run git gc right after a big rebase and find the old commits are still sitting there, reachable through `git reflog` even though no branch or tag points at them anymore.

🔎 The Problem

git rebase --onto main feature-base feature-branch
# feature-branch now points at the rebased commits

git log --all --oneline
# old pre-rebase commits don't show up here (unreachable from any ref)

git reflog
# ...but they're still listed here, and `git gc` won't prune them
# until the reflog's default 90-day expiry passes

✅ Fix: A Rebase –onto Leaving Orphaned Commits Behind

  • Treat this as expected behavior rather than a leak: the old commits are a safety net letting you recover the pre-rebase state with `git reflog` if the rebase went wrong, for as long as the reflog keeps them.
  • If you specifically need to reclaim the space or confirm nothing of value was left behind, run `git reflog expire –expire=now –all` followed by `git gc –prune=now` once you’re certain the rebase is correct.
  • Before doing that irreversible cleanup, diff the tip of the orphaned commits against your new rebased branch to confirm nothing was dropped or changed unexpectedly during the replay.

🚨 Why This Is Dangerous

  • Running an aggressive prune before you’re sure the rebase preserved everything removes your only safety net — once the reflog entries are gone and gc has run, those original commits are not coming back.

A rebase doesn’t delete your old commits — it just stops pointing at them, which is a very different thing until the day you actually need one back.

— Version Control Tip

Related posts:

Git Repositories Grow Too Fast

Git Repositories Grow Too Fast

Git: Use Git Stash to Save Work Temporarily

Git: Use Git Stash to Save Work Temporarily

Git: Use Git Pull to Update Your Local Repository

Git: Use Git Pull to Update Your Local Repository

Views: 5
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

Photoshop: Fix a Clone Stamp Aligned Mode Resetting Per Stroke
Asp.Net Core: Fix a Rate Limiter Resetting Its Window Too Early

Leave a Reply Cancel reply

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

Most Read

  1. 01How to make theater mode the default for Youtube 1,079 views
  2. 02How to add default value for Entity Framework migrations for DateTime and Bool 996 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 995 views
  4. 04Get the First and Last Word from a String or Sentence in SQL 873 views
  5. 05How to select distinct rows in a datatable in C# 866 views
  6. 06How to enable, disable and check if Service Broker is enabled on a database in SQL Server 671 views
  7. 07Add Constraint to SQL Table to ensure email contains @ 629 views
  8. 08Average of all values in a column that are not zero in SQL 584 views
  9. 09How to use Map Mode for Vertical Scroll Mode in Visual Studio 561 views
Bits of .NET

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

Social

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