我有一个特殊的需求,希望git将大多数文件扩展名视为二进制文件,只有少数例外。
我想将所有文件扩展名都视为二进制文件,例如.pdf .doc .xls等,除了纯文本文件如.txt .rb .py等。
我尝试像下面这样配置.gitattributes来看看它如何工作:
# cat .gitattributes
* binary
*.txt text
我一开始认为配置文件中的顺序很重要,但似乎并不是。使用上述配置后,所有文件仍然被视为二进制。
有没有一种方法可以通过配置 .gitattributes 文件或任何其他方式来将所有文件都以同一种方式处理,即作为二进制文件,除了一些例外情况?
更新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
更新2:
我认为crlf和text是相同的,即下面两个.gitattributes配置是相同的:
# cat .gitattributes
*.txt crlf diff
* binary
# cat .gitattributes
*.txt text diff
* binary
gitattribute
手册的“EXAMPLE”部分(http://www.kernel.org/pub/software/scm/git/docs/gitattributes.html#_example)很好地说明了这个规则。 - VonC*.txt text = auto
覆盖,您可以自行检查。但是我已经用-text
替换了binary
。 - Alex Zhukovskiy