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 a .gitattributes Line Ending Rule That Only Takes Effect on Files Checked Out After It Was Added

- 28.10.26 - ErcanOPAK

🔀 Fix a .gitattributes Line Ending Rule That Only Takes Effect on Files Checked Out After It Was Added

Adding a line ending rule to .gitattributes changes how Git will normalize files during future checkout and checkin operations – it does not reach backward and rewrite the line endings already sitting in files that are already committed and already present in your working tree. A file added to the repository before the rule existed keeps whatever line endings it already had until something actually causes Git to check it out again from scratch, which a simple edit to .gitattributes alone will never trigger on its own.

🔎 The Problem

$ cat .gitattributes
*.sh text eol=lf

$ git add .gitattributes
$ git commit -m "Normalize shell script line endings"

$ file scripts/deploy.sh
scripts/deploy.sh: ASCII text, with CRLF line terminators
# still CRLF - this file was committed before the rule
# existed and has never actually been re-checked-out since

✅ Fix: Force a Renormalization After Changing .gitattributes

  • After adding or changing a line ending rule, explicitly renormalize every already-tracked file against the new rule using the renormalize option on git add, rather than assuming the rule alone will eventually apply on its own.
  • Commit the resulting line ending changes as their own dedicated commit, separate from any unrelated feature work, so the renormalization doesn’t get buried inside an otherwise unrelated diff.
  • Warn collaborators before they pull a renormalization commit, since it can touch a large number of files purely due to line endings and is easy to mistake for unrelated, sweeping changes if nobody was told it was coming.

🚨 Why This Is Dangerous

  • A renormalization commit that touches many files at once can look alarming in review or in a diff tool if its purpose isn’t clearly labeled – state plainly in the commit message that it’s a pure line-ending normalization and nothing else changed.

.gitattributes describes how Git should treat files going forward – it was never going to reach back in time and fix the line endings already sitting in your history.

— Version Control Tip

Related posts:

Git: Undo a Bad git reset --hard and Get Your Commits Back

Git: Undo a Bad git reset --hard and Get Your Commits Back

Git: Fix a Shallow Clone in CI That Silently Produces the Wrong Version Number From git describe Bec...

Git: Fix a Shallow Clone in CI That Silently Produces the Wrong Version Number From git describe Bec...

Git: Fix a File That Keeps Reverting to an Old Version in Status and Diff Because assume-unchanged W...

Git: Fix a File That Keeps Reverting to an Old Version in Status and Diff Because assume-unchanged W...

Views: 9

Post navigation

Docker: Fix a Healthcheck That Reports unhealthy Forever Because Its Exec Form Command Needs a Shell That Doesn’t Exist in a Distroless Image
Visual Studio: Fix the Immediate Window Evaluating a Watch Expression Against the Wrong Stack Frame After You Switch Threads Mid-Debug

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 (981)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)
  • 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 @ (609)
  • Average of all values in a column that are not zero in SQL (570)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (547)
  • 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 (981)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)

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