为什么CRLF的git警告标记为二进制文件?

时间:2015-11-11 02:30:12

标签: git

我有一个标记为二进制文件的文件:

$ cat .gitattributes
dist/* binary
$ git check-attr -a ./dist/app.js
./dist/app.js: binary: set
./dist/app.js: diff: unset
./dist/app.js: merge: unset
./dist/app.js: text: auto

git diff正确将文件视为二进制文件:

$ git diff
diff --git a/dist/app.js b/dist/app.js
index 9c05798..fbcedd4 100644
Binary files a/dist/app.js and b/dist/app.js differ

但是当我运行git status时,我收到有关CRLF次转化的警告:

$ git status
warning: CRLF will be replaced by LF in dist/app.js.
The file will have its original line endings in your working directory.
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   dist/app.js

发生了什么事?为什么git警告我这个文件中的CRLF?

1 个答案:

答案 0 :(得分:1)

Git 2.10(2016年第3季度)应该更加小心二进制中的crlf。

commit 6523728Torsten Bögershausen (tboegi)(2016年6月28日) (由Junio C Hamano -- gitster --合并于commit 21bed62,2016年7月25日)

  

convert:统一CRLF的“auto”处理

     

在此更改之前,

$ echo "* text=auto" >.gitattributes
$ echo "* eol=crlf" >>.gitattributes
  

具有相同的效果
$ echo "* text" >.gitattributes
$ git config core.eol crlf
  

由于“eol”属性的优先级高于“text=auto”,因此可能损坏二进制文件,而不是大多数用户期望发生的

     

使'eol'属性服从'text = auto',现在

$ echo "* text=auto" >.gitattributes
$ echo "* eol=crlf" >>.gitattributes
  

的行为与

相同
$ echo "* text=auto" >.gitattributes
$ git config core.eol crlf

Git 2.13(2017年第2季度)确保规范化使用正确的命令
commit 8599974查看Torsten Bögershausen (tboegi)(2017年4月12日) Junio C Hamano -- gitster --于2017年4月24日commit 848d9a9合并)

trigger a re-normalization

  

从干净的工作目录:

$ echo "* text=auto" >.gitattributes
$ rm .git/index     # Remove the index to re-scan the working directory
$ git add .
$ git status        # Show files that will be normalized
$ git commit -m "Introduce end-of-line normalization"
相关问题