Fixing the line-endings in a Git repository using the `.gitattributes` file

前端 未结 1 1134
不知归路
不知归路 2021-01-13 17:11

What needs fixing:

I have a repository containing a single .md file, which contains an essay I am writing.

I edit the file from a few different

相关标签:
1条回答
  • 2021-01-13 17:53

    Try just using

    *.md text eol=native
    

    instead of

    *.md text
    

    in your .gitattributes.

    I did set up a small test repo with a CR-LF file in it and followed your first procedure to perform normalization:

    git rm --cached -r .
    git reset --hard
    git add .
    git commit -m "Normalize line endings"
    

    That correctly normalized file on check-in. But, weirdly, it still maintained CR-LF when checking-out, even if I am on OSX.

    Supposedly, default value for core.eol is native. So, I expected git to checkout my files using just LF. But it seems that for some reason, it's just not doing that. So, my understanding of .gitattributes is flawed, or we have a bug to be filed to git...

    In any case, explicitly setting eol=native in .gitattributes did the trick for me, as I said.

    0 讨论(0)
提交回复
热议问题