91

due to a "feature" in Microsoft's Visual Studio, .sln files must have windows style line endings so that the windows explorer could open them in Visual studio. So I need to be able to commit this one particular file with line endings intact. It is fine if all other files get converted. The question is how to make git accept just one single file with windows endings?

2 Answers 2

134

Take a look at the gitatttributes documentation. With recent versions of git, you can set the eol attribute for files to control what end-of-lines will be used when the file is checked out.

You should be able to create a .gitattributes file in your repository that looking something like:

path/to/my/file eol=crlf 
Sign up to request clarification or add additional context in comments.

4 Comments

Could you update the URL: git-scm.com/docs/gitattributes -- Thanks.
Updated! more words to make stackoverflow happy
Note: You might have to manually change the line endings and re commit the files as well
It's not necessary to recommit any files. You can also delete your local files and then revert the deletion using git checkout . That should restore the files with the desired line endings.
5

To ensure:

  • all .sln files are always checked out with CRLF line endings
  • but everything else git decides is not a binary file is checked out with LFs

...you can set up a .gitattributes file in the root of your project,like:

# Ensure all files are checked into the repo with LF line endings and checked # out with LFs. * text=auto eol=lf # Except these files will always be checked out with CRLFs (regardless of the # OS they were checked out on). *.bat text eol=crlf *.sln text eol=crlf 

This example also ensures .bat files always use CRLF line endings.

Note: If you're expecting to store binary files in your repo, like images, you may also want to explicitly tell git not to mess with line endings with something like *.png binary.

Note: Older versions of git had a bug in this area, so ensure you're using 2.10 or later.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.