如何查看git存储库中已存在哪种类型的行结尾?

时间:2016-03-04 16:23:48

标签: git github version-control bitbucket line-endings

首先,我不是在问它是什么意思或者如何改变它。我最感兴趣的是:我怎样才能看到已经存在的回购?什么类型的行结尾。

我在github和bitbucket上有我的存储库。

感谢您的帮助

3 个答案:

答案 0 :(得分:4)

将存储库源代码下载为.zip文件。启用后使用Notepad ++检查文件:

View->Show Symbol->Show End Of Line setting

答案 1 :(得分:3)

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.txt
some-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.txt
some-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.

答案 2 :(得分:3)

要确定存储库中文件正在使用的行尾,请使用git show提取文件的内容。这将为您提供内容,而无需更改行结尾

如果要查看本地工作目录中的文件(如其他答案之一),则只会告诉您检出的工作目录中的行尾。 Git可以并且通常在Windows上会在检出文件时更改行尾,并在提交文件后撤消更改。因此,即使存储库中的数据使用LF,您也会在工作目录中看到CR-LF。

使用git showgit cat-file -p将绕过此转换。

可以将git show的输出通过管道传输到文件,以使其自动检测行尾类型。 E.x。:

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

您可以将修订版从HEAD更改为其他版本,以查看旧修订版的行尾。例如查看它们是否已更改。