Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make git not change line endings for one particular file?

Tags:

git

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?

like image 363
akonsu Avatar asked Apr 27 '12 20:04

akonsu


People also ask

Does git change line endings?

However, it does not modify line endings in your working tree. This is essentially the same as setting core. autocrlf=input in your Git settings. More specifically, the text=auto option tells Git to only normalize line endings to LF for text files while leaving binary files (images, fonts, etc.)

How do I know if a file is LF or CRLF?

use a text editor like notepad++ that can help you with understanding the line ends. It will show you the line end formats used as either Unix(LF) or Macintosh(CR) or Windows(CR LF) on the task bar of the tool. you can also go to View->Show Symbol->Show End Of Line to display the line ends as LF/ CR LF/CR.

How does git store line endings?

Git store whole files as "blobs" and only do conversion when reading (checking out) or writing (indexing). Git does not store "neutralized lines". So yes, Git can save files with mixed line endings, but that's usually a bad practice to avoid.


1 Answers

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 
like image 84
larsks Avatar answered Sep 21 '22 21:09

larsks