git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Changing encoding of a file : What should happen to CRLF in file ?

From
ANAshish Negi <ashishnegi33@gmail.com>
Date
Nov 15, 2017, 19:05 UTC
Message-ID
<CAJ_+vJ7am7dU9B0qTYVtxpkHoZdV45ciZN5ifbv9W8xRO2o=EQ@mail.gmail.com>
In-Reply-To
<20171115171258.GA12963@tor.lan>
On windows :
> git --version
git version 2.14.2.windows.2
On linux :
> git --version
git version 2.7.4

I would like to understand the solution : If i understood it correctly : it removes file_name.txt from index, so git forgets about it. we then add the file again after changing encoding. This time, git takes it as utf-8 file and converts crlf to lf when storing it internally. Right ?

Thank you for the support.
On Wed, Nov 15, 2017 at 10:42 PM, Torsten Bögershausen <tboegi@web.de> wrote:
Show 49 quoted lines
> On Wed, Nov 15, 2017 at 01:41:42PM +0530, Ashish Negi wrote:
>> > If you commit the file, it will be stored with LF in the index,
>> This is what i believe is not happening.
>>
>> Lets do this with a public repository and steps which are reproducible.
>> I have created a repo : https://github.com/ashishnegi/git_encoding
>>
>> If you clone this repo in linux and run `git status`, you will find
>> that file is modified.
>
> This is what what I get:
>
>  git ls-files --eol
> i/lf    w/lf    attr/text=auto          .gitattributes
> i/crlf  w/crlf  attr/text=auto          file_name.txt
>
> (And you get the same, I think)
> Newer versions of Git (>=2.10) will -not- treat file_name.txt as changed,
> older versions do.
> What does "git --version" say on your Linux machine ?
>
> However, if you want to fix it, you want to either end up with
>
> A)
> git ls-files --eol
> i/lf    w/lf    attr/text=auto          .gitattributes
> i/lf    w/crlf  attr/text=auto          file_name.txt
>
> or
> B)
> git ls-files --eol
> i/lf    w/lf    attr/text=auto          .gitattributes
> i/crlf  w/crlf  attr/-text              file_name.txt
>
> (The "attr/-text" means "don't change the line endings")
>
> Both A) or B) will work, typically A) is preferred.
>
> You should be able to achive A) :
>  git rm --cached file_name.txt  && git add file_name.txt
> rm 'file_name.txt'
> warning: CRLF will be replaced by LF in file_name.txt.
> The file will have its original line endings in your working directory.
>
> git ls-files --eol
> i/lf    w/lf    attr/text=auto          .gitattributes
> i/lf    w/crlf  attr/text=auto          file_name.txt
>
> [snip the rest]
Previous: Torsten BögershausenNext: Torsten Bögershausen
Message 8 of 23 in “Changing encoding of a file : What should happen to CRLF in file ?”
  1. Ashish NegiNov 14, 2017
  2. Torsten BögershausenNov 14, 2017
  3. Ashish NegiNov 14, 2017
  4. Ashish NegiNov 14, 2017
  5. Torsten BögershausenNov 14, 2017
  6. Ashish NegiNov 15, 2017
  7. Torsten BögershausenNov 15, 2017
  8. Ashish NegiNov 15, 2017
  9. Torsten BögershausenNov 16, 2017
  10. Ashish NegiNov 23, 2017
  11. Torsten BögershausenNov 23, 2017
  12. Ashish NegiNov 24, 2017
  13. Torsten BögershausenNov 14, 2017
  14. 1/1 convert: tighten the safe autocrlf handlingtboegi@web.de, Nov 24, 2017
  15. Eric SunshineNov 24, 2017
  16. Torsten BögershausenNov 24, 2017
  17. Junio C HamanoNov 25, 2017
  18. 1/1 convert: tighten the safe autocrlf handlingtboegi@web.de, Nov 26, 2017
  19. 1/2 t0027: Don't use git commit <empty-pathspec>tboegi@web.de, Dec 8, 2017
  20. Junio C HamanoDec 8, 2017
  21. Junio C HamanoDec 8, 2017
  22. Torsten BögershausenDec 8, 2017
  23. 2/2 t0027: Adapt the new MIX tests to Windowstboegi@web.de, Dec 8, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.