Is there a way to determine the line endings in a existing git repo?

后端 未结 4 2100
轮回少年
轮回少年 2020-12-16 10:17

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

相关标签:
4条回答
  • 2020-12-16 10:39

    The best line endings practice is here: https://stackoverflow.com/a/10855862

    To determine the line endings in a existing git repository:

    1. Set core.autocrlf to false, so it will not change file endings while transmitting files.
    2. git clone your repo for ex. in a new directory.
    3. Use the text editor that shows line endings to open the files (for ex. PHPStorm does). You should open several files as line endings may differ from file to file.

    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.

    0 讨论(0)
  • 2020-12-16 10:47

    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.

    0 讨论(0)
  • 2020-12-16 10:56

    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:

    • set core.autocrlf to true
    • git clone your repo
    • git 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
    
    0 讨论(0)
  • 2020-12-16 11:03

    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.)

    0 讨论(0)
提交回复
热议问题