Is there a way to determine the line endings in a existing git repository?
If I clone a existing repository how do I determine what core.autocrlf was used by the cre
The best line endings practice is here: https://stackoverflow.com/a/10855862
To determine the line endings in a existing git repository:
core.autocrlf
to false
, so it will not change file endings while transmitting files.git clone
your repo for ex. in a new directory.You can't determine what core.autocrlf was used by the creator as it is local config except the repo has .gitattributes file.
On Windows if you are not using .gitattributes just use core.autocrlf true as it set by default.
In Windows, just run the below command from the command prompt:
git config --list
This will list all the git configuration variables.
If you want to get the individual config setting (e.g. for core.autocrlf), run the following command on the windows command prompt:
git config --get core.autocrlf
This will either give you a "true
" OR "false
" value.
IF you wish to change this, edit C:\ProgramData\Git\config
file, and change the value from false
to true
Note: This only applies for Windows operating systems.
I would still maintain that setting (core.autocrlf
) to false
, as I explain in " Distributing git configuration with the code" that you mention, and uses eol gitattributes directive for a more fine-grained control.
That being said, to detect a mixed line endings:
core.autocrlf
to true
git clone
your repogit diff
: if diffs are visible just after your clone... some automatic eol conversions just took place in the working tree.Update 2016 (4 years later): a more modern way to detect eol changes:
git -c color.diff.whitespace="red reverse" diff -R -- afile
To check what line endings were actually committed in the repository (regardless of your core.autocrlf
setting), try the following:
git grep -I --files-with-matches --perl-regexp '\r' HEAD
(-I
means that binary files should not be looked at.)