Trying to fix line-endings with git filter-branch, but having no luck

后端 未结 8 894
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 09:02

I have been bitten by the Windows/Linux line-ending issue with git. It seems, via GitHub, MSysGit, and other sources, that the best solution is to have your local repos set

8条回答
  •  耶瑟儿~
    2020-11-22 09:38

    The git documentation for gitattributes now documents another approach for "fixing" or normalizing all the line endings in your project. Here's the gist of it:

    $ echo "* text=auto" >.gitattributes
    $ git add --renormalize .
    $ git status        # Show files that will be normalized
    $ git commit -m "Introduce end-of-line normalization"
    

    If any files that should not be normalized show up in git status, unset their text attribute before running git add -u.

    manual.pdf -text

    Conversely, text files that git does not detect can have normalization enabled manually.

    weirdchars.txt text

    This leverages a new --renormalize flag added in git v2.16.0, released Jan 2018. For older versions of git, there are a few more steps:

    $ echo "* text=auto" >>.gitattributes
    $ rm .git/index     # Remove the index to force git to
    $ git reset         # re-scan the working directory
    $ git status        # Show files that will be normalized
    $ git add -u
    $ git add .gitattributes
    $ git commit -m "Introduce end-of-line normalization"
    

提交回复
热议问题