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 grep Missing a Match Inside a File Because the Repository’s .gitattributes Marks That Path as Binary

- 05.11.26 - ErcanOPAK

🔀 Git: Fix git grep Missing a Match Inside a File Because the Repository’s .gitattributes Marks That Path as Binary

git grep, like diff and most other text-oriented Git plumbing, skips any path Git’s attribute system considers binary — determined either by content-sniffing or, more commonly in a configured repository, by an explicit -diff/binary attribute set in .gitattributes for a path pattern. A plain-text file that happens to match a broad glob meant for genuinely binary files — a *.dat pattern intended for compiled fixtures that also happens to match a text config.dat — gets silently treated as binary by every text-based Git command, so git grep simply never searches its content and reports no match, with nothing telling you the file was skipped rather than searched and found clean.

🔎 The Problem

# .gitattributes
*.dat binary

# config.dat is actually plain text, but matches the glob anyway:
$ git grep "legacy_api_key"
# (no results at all, even though config.dat contains the string)

$ git check-attr -a -- config.dat
config.dat: diff: unset
config.dat: binary: set
# <- this is why git grep silently skipped it

✅ Fix: Check .gitattributes Before Trusting a Clean Grep

  • Run git check-attr -a -- <path> on a suspiciously grep-invisible file to see exactly which .gitattributes rule marks it binary, before assuming the content itself just doesn’t contain your search term.
  • Narrow an overly broad glob in .gitattributes (like *.dat binary) to the specific directory or more specific pattern that actually contains binary fixtures, rather than a wildcard that can catch a legitimate text file by coincidence.
  • Pass git grep -a (treat all files as text) when you specifically need to search across files you suspect might be misclassified, as a one-off override without changing the repository’s .gitattributes itself.

🚨 Why This Is Dangerous

  • A security or configuration audit that greps the whole repository for a leaked credential or deprecated setting can report a clean result while a matching file sits right there untouched, simply because it was never actually searched — and a clean grep result is exactly the kind of thing nobody double-checks.

git grep doesn’t report a file as clean — it reports a file as skipped, and a .gitattributes rule is the only thing standing between those two very different outcomes.

— Version Control Tip

Related posts:

Git: Use Git Bisect to Find Bugs with Binary Search

Git: Use Git Bisect to Find Bugs with Binary Search

Git: Use git log --graph to Visualize Branch History

Git: Use git log --graph to Visualize Branch History

Git: Recover From Committing to the Wrong Branch by Accident

Git: Recover From Committing to the Wrong Branch by Accident

Views: 7

Post navigation

WordPress: Fix a Multisite Network’s Shared Media Library Returning 403 for Subsites Because the Uploads Path Rewrite Only Covers the Main Site’s Domain
The AI Prompt That Checks Your Soft-Delete Queries for a Forgotten WHERE Clause That Lets Deleted Rows Leak Back Into a Report

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