How to normalize working tree line endings in Git?

后端 未结 6 1999
甜味超标
甜味超标 2020-11-28 01:17

I have cloned a repository that had inconsistend line endings. I have added a .gitattributes that sets the text attribute for the files I want to normalize. Now

6条回答
  •  旧时难觅i
    2020-11-28 02:00

    Alternative approach (differs only in command used)

    Make sure you have no any pending changes in repository:

    $ git status
    $ git stash
    

    Modify .gitattributes so CRLF interpretation will changed:

    $ echo "*.txt  text" >>.gitattributes
    $ git commit -m "Made .txt files a subject to CRLF normalization." -- .gitattributes
    

    Remove data from index and refresh working directory:

    $ git rm --cached -r .
    $ git reset --hard
    

    Review CRLF fixes that Git proposes:

    $ git ls-files --eol
    $ git status
    $ git diff
    

    Agree with Git decision:

    $ git add -u
    $ git commit -m "Normalized CRLF for .txt files"
    

    Reload changes as if clean clone was done:

    $ git rm --cached -r .
    $ git reset --hard
    

提交回复
热议问题