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: Fix git diff –color-moved Silently Failing to Detect a Moved Block Because Reindentation Changed Every Line’s Leading Whitespace

- 02.11.26 - ErcanOPAK

🔀 Fix git diff –color-moved Silently Failing to Detect a Moved Block Because Reindentation Changed Every Line’s Leading Whitespace

git diff --color-moved highlights lines that were moved rather than changed by matching blocks of identical lines between the old and new side of a diff, and its default mode requires an exact character-for-character match, including leading whitespace. A block of code moved to a new location and reindented in the same commit — extremely common when wrapping a function in a new conditional or nesting it inside a class — no longer matches its old self character-for-character, so Git falls back to showing the whole thing as a plain deletion plus addition instead of a highlighted move, hiding the fact that a reviewer is actually looking at the same logic relocated, not new logic that needs line-by-line scrutiny.

🔎 The Problem

$ git diff --color-moved
-function calculateTotal(items) {
-  return items.reduce((a, b) => a + b.price, 0);
-}
+  function calculateTotal(items) {
+    return items.reduce((a, b) => a + b.price, 0);
+  }
# Exact same logic, moved one nesting level deeper and reindented -
# shown as a plain removal + addition, NOT highlighted as a move

$ git diff --color-moved --color-moved-ws=allow-indentation-change
# Same two blocks now correctly highlighted in move-color, since the
# comparison ignores the leading-whitespace change from reindentation

✅ Fix: Compare Moved Blocks While Ignoring Whitespace Changes

  • Add --color-moved-ws=allow-indentation-change alongside --color-moved so Git’s move-detection compares lines after normalizing whitespace differences, exactly the case a reindented-and-moved block needs to be recognized correctly.
  • Set diff.colorMovedWS in git config to allow-indentation-change as a sensible default, rather than remembering to pass the flag by hand every time you review a refactor-heavy commit.
  • When reviewing a pull request in a web UI instead of the CLI, check whether that platform’s own move-detection or whitespace-hiding view is enabled, since the same exact-match limitation applies there independently of your local git config.

🚨 Why This Is Dangerous

  • A reviewer who doesn’t realize color-moved missed a relocation ends up re-reviewing already-correct logic line by line as if it were newly written, wasting review time at best, or approving a diff without noticing that the “new” code silently dropped a line during the reindent that an actual move-aware diff would have made obvious by comparison.

git diff –color-moved only recognizes a moved block as the same lines you already approved once if every character, including the whitespace in front of it, still matches — reindent it in the same commit, and as far as the default diff is concerned, it’s a brand new block.

— Version Control Tip

Related posts:

Git: Resolve Merge Conflicts Like a Pro

Git: Resolve Merge Conflicts Like a Pro

Git: Use git switch and git restore Instead of Confusing git checkout

Git: Use git switch and git restore Instead of Confusing git checkout

Git: Use git notes to Add Comments to Commits Without Changing History

Git: Use git notes to Add Comments to Commits Without Changing History

Views: 8

Post navigation

The AI Prompt That Turns a Homeowner’s Stack of Contractor Renovation Quotes Into One Apples-to-Apples Comparison Table
Docker: Fix a Compose Stack Silently Reusing a Stale Anonymous Volume Because a Service Was Renamed Without Renaming Its Volume

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,055)
  • Get the User Name and Domain Name from an Email Address in SQL (980)
  • How to add default value for Entity Framework migrations for DateTime and Bool (976)
  • Get the First and Last Word from a String or Sentence in SQL (857)
  • How to select distinct rows in a datatable in C# (852)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (653)
  • Add Constraint to SQL Table to ensure email contains @ (607)
  • Average of all values in a column that are not zero in SQL (569)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (546)
  • Find numbers with more than two decimal places in SQL (475)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit
  • SQL Server: Fix ROW_NUMBER Ties Reordering Between Identical Runs
  • C#: Fix an Enum HasFlag Returning True for the Zero Value
  • WordPress: Fix Featured Images Vanishing After a CDN Migration
  • Photoshop: Fix Content-Aware Fill Smearing a Repeating Pattern
  • Asp.Net Core: Fix Antiforgery Tokens Rejected Behind a Reverse Proxy

Most Viewed Posts

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

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit

Social

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