我特别需要git将大多数文件扩展名视为二进制文件,除了一些扩展名.
我想将所有文件扩展名视为二进制文件,.pdf .doc .xls等,除了.txt .rb .py等纯文本文件.
我已经尝试过如下配置.gitattributes来看看它是如何工作的:
# cat .gitattributes
* binary
*.txt text
Run Code Online (Sandbox Code Playgroud)
我想也许配置文件中的顺序很重要,但似乎没有.使用上述配置,所有文件仍被视为二进制文件.
有没有办法配置.gitattributes或git以任何其他方式将所有文件作为二进制处理,除了一些例外?
更新1:
我尝试了下面描述的.gitattributes.有用!
# cat .gitattributes
*.txt crlf diff
* binary
# git diff
diff --git a/file b/file
index d929b94..bee5cb1 100644
Binary files a/file and b/file differ
diff --git a/file.txt b/file.txt
index 632ae98..93d22b0 100644
--- a/file.txt
+++ b/file.txt
@@ -1 +1,3 @@
Hey this is a .txt file
+Adding another line
+A new line
Run Code Online (Sandbox Code Playgroud)
更新2:
我相信crlf和text是相同的,即.gitattributes的以下两个配置是相同的:
# cat .gitattributes
*.txt crlf diff
* binary
# cat .gitattributes
*.txt text diff
* binary
Run Code Online (Sandbox Code Playgroud)
Von*_*onC 20
binary是一个宏设置属性crlf和diff(实际上在这里取消设置)
请参见手册页中的 " 使用属性MACROS " ..gitattribute
设置或取消设置属性后,如果后续规则无法更改.
所以你可以尝试:
* binary
*.txt crlf diff
Run Code Online (Sandbox Code Playgroud)
这样,crlf并且diff为*.txt文件设置,对于那些相同的文件,它们将不会被二进制宏取消设置*.txt,而对于所有其他文件它们将被取消设置.
从2009年提交b9d14ff开始,这些规则应该是: