Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git stash: prevent converting line separators

Tags:

git

In my normal core.autocrlf=true repositories on Windows I had a file with \n line separators (intentionally). After saving as a stash and applying it later, it was changed back to \r\n which was a little bit unexpected for me.

How can I make saving and applying a stash not convert any line separator but keep the files as is?

like image 474
Thomas S. Avatar asked Mar 21 '26 02:03

Thomas S.


2 Answers

Before stash , you can turn off the crlf conversion.

git config --global core.autocrlf false

You can turn it back after you apply stash.

like image 132
TruckDriver Avatar answered Mar 23 '26 17:03

TruckDriver


You can use .gitattributes or .git/info/attributes to change CRLF handling on specific files. For example,

*.special text eol=lf

will always convert to \n in the Git repository. See man gitattributes for more.

like image 39
ephemient Avatar answered Mar 23 '26 16:03

ephemient