2

Previously, I had my .gitattributes set up like so:

* text=auto

On Windows, unfortunately this resulted in my *.sh files being checked out with CRLF line endings. To correct this, my .gitattributes now look like:

* text=auto
*.sh eol=lf

I'm using Git version 2.24 on Windows 10.

Is there a mechanism where I can, either for the whole local repo or specific directories inside of it, have all files matching new rules in .gitattributes "re-checked-out" so that the line endings (in this case) for *.sh files convert from CRLF to LF?

void.pointer
  • 24,859
  • 31
  • 132
  • 243
  • Unfortunately the linked answer doesn't help me @phd. It's difficult to tell in the post, but I believe they are referring to fixing line endings in the *repository*, not line endings in the working directory. `add --renormalize` would fix line endings in the repository, not the files checked out in the working copy. – void.pointer Jan 13 '20 at 15:28
  • Worth stating explicitly: The `*.sh` files already have LF line endings *inside the repo*, because of the rule `* text=auto`. However on Windows, all files check out to CRLF line endings unless certain configuration settings are specified *or* you set their EOL explicitly via `eol=lf` in `.gitattributes`. For the purposes of my question, assume none of those relevant Git configuration settings are specified. I am only focused on `.gitattributes`. – void.pointer Jan 13 '20 at 15:31
  • @phd Like I said, that doesn't work. I tried it just to be sure. Those instructions are for converting the line endings of files in the repository, not the line endings of files checked out in the working copy. So `git reset --hard && git add --renormalize .` doesn't work here. – void.pointer Jan 13 '20 at 15:34
  • https://stackoverflow.com/a/57300420/7976758 – phd Jan 13 '20 at 15:48
  • According to [the docs](https://git-scm.com/docs/git-add) renormalize is for this. Also [this answer](https://stackoverflow.com/a/54593760/3700414) explains well how renormalize acts on the metadata level. So in short what goes wrong with just "git add --renormalize . " (no reset)? – Rusi Jan 15 '20 at 16:10
  • @Rusi: I'm not sure how I could explain it much better than I have with my previous comments. I want to fix line endings in my working copy, *not* in the index. `git add --renormalize` fixes line endings in the index. It does not force Git to re-checkout the files in my working copy with correct line endings. – void.pointer Jan 23 '20 at 15:22

1 Answers1

2

You could remove them and then run git checkout -- blah.sh to get it back.

eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • I was expecting a more built in solution, but it's apparent to me that doesn't exist. You have provided a simple, straightforward solution. – void.pointer Jan 23 '20 at 15:23