Re: Changing encoding of a file : What should happen to CRLF in file ?
- From
Torsten Bögershausen <tboegi@web.de>
- Date
- Nov 15, 2017, 17:12 UTC
- Message-ID
- <20171115171258.GA12963@tor.lan>
- In-Reply-To
- <CAJ_+vJ6SxLOmZfG79Sa-vskBR-XG=C97--PB-vpijjUKym=jYw@mail.gmail.com>
On Wed, Nov 15, 2017 at 01:41:42PM +0530, Ashish Negi wrote:
Show 8 quoted lines
> > 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]