What's the best CRLF (carriage return, line feed) handling strategy with Git?

后端 未结 9 1758
青春惊慌失措
青春惊慌失措 2020-11-22 07:30

I tried committing files with CRLF-ending lines, but it failed.

I spent a whole work day on my Windows computer trying different strategies and was almost drawn to s

9条回答
  •  抹茶落季
    2020-11-22 08:13

    Try setting the core.autocrlf configuration option to true. Also have a look at the core.safecrlf option.

    Actually it sounds like core.safecrlf might already be set in your repository, because (emphasis mine):

    If this is not the case for the current setting of core.autocrlf, git will reject the file.

    If this is the case, then you might want to check that your text editor is configured to use line endings consistently. You will likely run into problems if a text file contains a mixture of LF and CRLF line endings.

    Finally, I feel that the recommendation to simply "use what you're given" and use LF terminated lines on Windows will cause more problems than it solves. Git has the above options to try to handle line endings in a sensible way, so it makes sense to use them.

提交回复
热议问题