How to see what type of line endings are already in git repository?
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.
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
Line endings are an attribute of files, not repositories (and technically they can even be mixed within the same file). To see what type of line endings a particular file has you can use something like the file
command on a Linux system (which should also work on OSX):
$ file some-file.txtsome-file.txt: ASCII text
This indicates that the line endings match the system default, so in my case it would be unix line endings. Windows line endings would show up like this:
$ file some-file.txtsome-file.txt: ASCII text, with CRLF line terminators
Alternatively, open the file in a decent text-editor. Most will have a way to show you the line ending style. For example, Emacs shows
U(DOS)
in the modeline for the second example above, indicating CRLF ("DOS") line endings. Most other editors will have something similar.
If you want to see the core.autocrlf
setting for a particular repository, run git config core.autocrlf
inside it. You'll get back the value it's set to, or nothing if it is unset. These settings are local to the repository (i.e. not shared with GitHub, Bitbucket, or other users' local copies).
You might also want to inspect the repository's .gitattributes
or .git/info/attributes
files, if either exists. The former is stored as a regular file in the repository, so would be shared with other people, and the latter is specific to your local repository.