为什么在标记为二进制文件的文件上使用CRLF的git警告? [英] Why is git warning of CRLF on a file flagged as binary?
问题描述
$ 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
索引9c05798..fbcedd4 100644
二进制文件a / dist /app.js和b / dist / app.js不同
但是当我运行 git status
,我得到了关于 CRLF
转换的警告:
$ git status
警告:在dist / app.js中,CRLF将被替换为LF。
该文件将在工作目录中具有其原始行结尾。
在分支大师
上你的分支是最新的'origin / master'。
要提交的更改:
(使用git reset HEAD< file> ...停用)
修改:dist / app.js
发生了什么事?为什么git会在这个文件中警告我关于CRLF的问题?
Git 2.10(Q3 2016) 。
请参阅 commit 6523728 (2016年6月28日)作者: TorstenBögershausen( tboegi
)。
(由 Junio C Hamano - gitster
- 在 commit 21bed62 ,7月25日2016)
$ b
convert
:统一auto
处理CRLF
在此更改之前,
$ echo* text = auto> .gitattributes
$ echo* eol = crlf>> ; .gitattributes
的作用与
$ echo* text> .gitattributes
$ git config core.eol crlf
由于'
eol
'属性的优先级高于'text = auto
',这可能会破坏二进制文件,而不是大多数用户期望发生的。 p>
使'eol'属性符合'text = auto'和现在
$ echo* text = auto> .gitattributes
$ echo* eol = crlf>> .gitattributes
的行为与
相同
$ echo* text = auto> .gitattributes
$ git config core.eol crlf
Git 2.13(Q2 2017)确保规范化使用正确的命令
参见提交8599974 (2017年4月12日)作者: TorstenBögershausen( tboegi
)。
(由 Junio C Hamano - gitster
- in commit 848d9a9 ,2017年4月24日)
从一个干净的工作目录:
$ echo* text = auto> .gitattributes
$ rm .git / index#删除索引以重新扫描工作目录
$ git add 。
$ git status#显示将被标准化的文件
$ git commit -m引入行尾标准化
I've got a file which has been flagged as binary:
$ 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
And git diff
correctly treats the file as binary:
$ 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
But when I run git status
, I get a warning about CRLF
conversions:
$ 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
What's going on? Why is git warning me about CRLFs in this file?
Git 2.10 (Q3 2016) should be more careful about crlf in binary.
See commit 6523728 (28 Jun 2016) by Torsten Bögershausen (tboegi
).
(Merged by Junio C Hamano -- gitster
-- in commit 21bed62, 25 Jul 2016)
convert
: unify the "auto
" handling of CRLFBefore this change,
$ echo "* text=auto" >.gitattributes
$ echo "* eol=crlf" >>.gitattributes
would have the same effect as
$ echo "* text" >.gitattributes
$ git config core.eol crlf
Since the '
eol
' attribute had higher priority than 'text=auto
', this may corrupt binary files and is not what most users expect to happen.Make the 'eol' attribute to obey 'text=auto' and now
$ echo "* text=auto" >.gitattributes
$ echo "* eol=crlf" >>.gitattributes
behaves the same as
$ echo "* text=auto" >.gitattributes
$ git config core.eol crlf
Git 2.13 (Q2 2017) makes sure the normalization uses the right commands
See commit 8599974 (12 Apr 2017) by Torsten Bögershausen (tboegi
).
(Merged by Junio C Hamano -- gitster
-- in commit 848d9a9, 24 Apr 2017)
To trigger a re-normalization:
From a clean working directory:
$ 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"
这篇关于为什么在标记为二进制文件的文件上使用CRLF的git警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!