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 Merge Commit That Silently Drops a File Because Both Branches Deleted It Differently

- 04.10.26 - ErcanOPAK

🔀 The File Two Branches Both Agreed to Lose

Git’s three-way merge treats a file as cleanly resolved, with no conflict markers and no manual intervention needed, whenever both sides of the merge agree on the outcome for that file – and two branches that each independently deleted the same file, for entirely different and unrelated reasons, count as agreeing as far as the merge algorithm is concerned. One branch might have deleted a configuration file because it was replaced by a new settings system, while an unrelated branch deleted the same file because it moved into a different folder under a new name – the merge sees two deletions of the same path and completes without a single conflict, even though the second branch actually still needed that file to exist, just somewhere else.

🔎 The Problem

$ git log --oneline --graph --all
*   a1b2c3d (HEAD -> main) Merge branch 'rename-config'
|\
| * d4e5f6a (rename-config) Move legacy.config to config/app.config
* | 9f8e7d6 (remove-dead-code) Delete legacy.config (dead feature)
|/
* 1234567 Base commit with legacy.config present

$ git show a1b2c3d --stat
# No conflict was ever reported during this merge - 'legacy.config'
# simply disappears from the tree, because both branches agree it
# should no longer exist at that path. The rename-config branch's
# actual intent - that the FILE still exists, under config/app.config
# - is invisible to a merge algorithm that only ever compares paths,
# never file content moved to a new location.

$ git show a1b2c3d -- config/app.config
# fatal: path 'config/app.config' does not exist in 'a1b2c3d' either -
# the rename branch's new file was never actually merged in, because
# it lived on a commit this merge's history graph never touched.

✅ Fix: Treat a Clean Merge as a Starting Point, Not Proof of Correctness

  • Diff the merge commit against each of its two parents individually right after merging, specifically looking for any file that disappears relative to one parent, since a clean merge’s absence of conflict markers never checks for this kind of cross-branch rename.
  • Use a rename-detection-aware diff, or review the actual commit history of a deleted file on each branch, before merging two long-lived branches that both touched the same area of the codebase, so an intentional rename on one side is caught before the merge silently erases it.
  • Run the test suite, and specifically any test that loads configuration or data from a file path, immediately after a merge that touched shared infrastructure files, rather than trusting a conflict-free merge to mean every file ended up where it needed to be.

⚠️ Why This Is Easy to Miss

  • A merge with zero conflicts reads as the safe, boring outcome – the kind every developer wants to see – so there is no natural prompt to go back and double-check individual files once the merge command itself reports success with nothing to resolve.
  • The missing file only causes a visible failure once something tries to load it at runtime, which can be long after the merge itself, especially if the file is only read in a code path or environment that isn’t exercised by routine local testing.

Git calls a merge clean when both branches agree – it never asks whether what they agree on is actually what either branch meant.

— Version Control Tip

Related posts:

ignoring any 'bin' directory on a git project

ignoring any 'bin' directory on a git project

Git: Find and Remove Sensitive Data from Entire Repository History

Git: Find and Remove Sensitive Data from Entire Repository History

Git: Fix a git add -p Session That Silently Stages the Wrong Hunk Because the File Changed Again Bef...

Git: Fix a git add -p Session That Silently Stages the Wrong Hunk Because the File Changed Again Bef...

Views: 15
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

HTML5: Fix a Native Lazy-Loading Image That Never Loads Because It Sits Inside a Hidden Tab Until the User Clicks It
CSS: Fix a prefers-color-scheme Media Query That Gets Silently Overridden by a Browser Extension’s Forced Dark Mode

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 997 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 996 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# 868 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 @ 631 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 562 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