Git: Removing carriage returns from source-controlled files

后端 未结 4 538
北恋
北恋 2020-12-24 00:22

I\'ve got a Git repository that has some files with DOS format (\\r\\n line endings). I would like to just run the files through dos2unix (which wo

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-24 01:20

    This crlf thing drove us crazy when we converted from svn to git (in a central (bare) like) scm environment. The thing that ultimately got us was we copied the global .gitconfig file to everyone's user root (yep both windows and linux) with the initial one coming from a Windows system and having core.autocrlf=true and core.safecrlf=false which played havoc on the linux users (like bash scripts didn't work and all those awful ^M's). So we initially did a checkout and clone script that did a dos2unix after these commands. Then I ran across the core.autocrlf and core.safecrlf config items and set them based on the O/S:

    Windows: core.autocrlf=true and core.safecrlf=false Linux: core.autocrlf=input and core.safecrlf=false

    These were set with: ---on Windows---

    git config --global core.autocrlf true
    git config --global core.safecrlf false
    

    ---on Linux---

    git config --global core.autocrlf input
    git config --global core.safecrlf false
    

    Then for our Linux developers we setup a little bash script /usr/local/bin/gitfixcrlf:

    #!/bin/sh
    # remove local tree
    git ls-files -z | xargs -0 rm
    # checkout with proper crlf
    git checkout .
    

    Which they only had to run on their local sandbox clones once. Any future cloning was done correctly. Any future push pulls now were handled correctly. So, this solved our multiple O/S issues with linefeeds. Also Note that Mac falls in the same config as Linux.

提交回复
热议问题