Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see what type of line endings are already in git repository?

First of all, I'm not asking what does it mean or how to change it. The thing what interest me most is: how can I see what's already in repo? What type of line endings.

I have my repositories on github and bitbucket.

Thanks for help

like image 652
Ivan Bara Avatar asked Mar 04 '16 16:03

Ivan Bara


People also ask

What line endings does git use?

This is a good default option. text eol=crlf Git will always convert line endings to CRLF on checkout. You should use this for files that must keep CRLF endings, even on OSX or Linux. text eol=lf Git will always convert line endings to LF on checkout.

How do you find the end of a line file?

Try file -k Short version: file -k somefile. txt will tell you. It will output with CRLF line endings for DOS/Windows line endings. It will output with CR line endings for MAC line endings.

Does git use LF or CRLF?

Git doesn't expect you to use unix-style LF under Windows. The warning "CRLF will be replaced by LF" says that you (having autocrlf = input ) will lose your windows-style CRLF after a commit-checkout cycle (it will be replaced by unix-style LF). Don't use input under Windows.

Does git store line endings?

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.


Video Answer


3 Answers

To tell what line endings a file in the repository is using, use git show to extract the file's contents. This will give you the contents without changing the line endings.

If you were to look at the files in your local working directory, as in one of the other answers, that only tells you what line endings are in the checked out working directory. Git can, and on Windows usually will, change the line endings when files are checked out and reverse the change when they are committed. So you will see CR-LF in the working directory even though the data in the repository uses LF.

Using git show or git cat-file -p will bypass this conversion.

The output of git show can be piped to file to have it automatically detect the line ending type. E.x.:

git show HEAD:file.c | file -
/dev/stdin: ASCII text, with CRLF line terminators

You can change the revision from HEAD to something else to see what the line endings were on an older revision. For instance to see if they have changed.

like image 93
TrentP Avatar answered Oct 19 '22 05:10

TrentP


You can use this command:

git ls-files --eol

It will output one line per file with the following information:

i/lf    w/crlf  attr/text=auto eol=lf   file.txt

In that example, i/lf means that the file uses lf in the index, and w/crlf means it uses crlf in the working directory.

like image 25
Flavien Avatar answered Oct 19 '22 06:10

Flavien


Download the repository source code as a .zip file. Use Notepad++ to check the files after enabling:

View->Show Symbol->Show End Of Line setting
like image 12
Taylan Karaman Avatar answered Oct 19 '22 06:10

Taylan Karaman