在GIT中仅将一个文件强制为二进制文件 [英] Force just one file as binary in GIT
问题描述
我需要将文件添加到git存储库,并且需要正确的行尾类型.
I need to add a file to a git repository, and I need the correct type of line ending.
在perforce中,我只会使用" -t binary
"将文件强制为二进制文件,但是我不知道如何在GIT中将文件设置为二进制文件.
存储库相当大,因此我不想进行全局更改.
新文件是 .html
,我已经有成千上万的 .html
文件,它们的类型我不想更改.
我也没有选择新文件的名称.
In perforce, I would just use "-t binary
" to force the file to binary, but I don't know how to set the file to binary in GIT.
The repository is rather large, so I don't want to make a global change.
The new file is .html
, and I already have thousands of .html
files whose type I don't want to change.
I don't have a choice about the name for the new file either.
那么,如何在不进行全局更改的情况下将一个文件强制转换为git中的二进制文件?
So, how do I force just one file to binary in git without making global changes?
推荐答案
you can record your file in a .gitattributes
file (that you can put in the same directory as your file):
yourFile.html binary
与以下相同:
yourFile.html -crlf -diff
yourFile.html -text -diff
这与 core.eol
指令(在同一 .gitattributes
文件):
This is slightly different than core.eol
directive (in that same .gitattributes
file):
yourFile.html eol=lf
这将自动更正 git checkout
上的行尾.
您不需要这种情况: binary
就足够了.
That would autocorrect end of lines on git checkout
.
You don't need that in your case: binary
is enough.
更多信息,请参见处理行尾".
这篇关于在GIT中仅将一个文件强制为二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!