git的.gitattributes可以将所有文件视为二进制文件,只有少数例外情况? [英] Can git's .gitattributes treat all files as binary except a few exceptions?
问题描述
我特别需要git将大多数文件扩展名视为二进制文件,除了一些扩展名。
我想将所有文件扩展名视为二进制文件。 pdf .doc .xls等,纯文本文件如.txt .rb .py等。
我已经尝试配置.gitattributes,如下所示,以了解如何可能会有效:
pre code $#$ .gitattributes
* binary
* .txt text
我想也许配置文件中的顺序很重要,但看起来并不如此。通过上述配置,所有文件仍然被视为二进制文件。
有没有一种方法可以配置.gitattributes或git以任何其他方式将所有文件作为二进制文件进行处理,除少数例外情况外?
更新1:
我尝试了下面介绍的.gitattributes。它可以工作!
#cat .gitattributes
* .txt crlf diff
* binary
#git diff
diff --git a / file b / file
索引d929b94..bee5cb1 100644
二进制文件a /文件和b /文件不同
diff --git a / file.txt b / file.txt
索引632ae98..93d22b0 100644
--- a / file.txt
+++ b / file.txt
@@ -1 +1,3 @@
这是一个.txt文件
+添加另一行
+新行
更新2:
我相信crlf和文本是相同的,即下面两个配置的.gitattributes是相同的:
pre $ cat $ g $ cat $ $ b * .txt crlf diff
* binary
$ b $ cat #gitattributes
* .txt text diff
* binary
请参阅
使用ATTRIBUTE MACROS
> .gitattribute 手册页。 属性设置或取消设置后,如果不能被随后的规则更改
所以你可以试试:
* binary
* .txt crlf diff
这样, crlf
并且为 *。txt
文件设置 diff
,这些文件不会被二进制宏取消, code> *。txt 文件,而对于所有其他文件,它们将被取消设置。
从 2009 commit b9d14ff ,那些规则应该是:
- 从更普遍的那些
- 更具体的。
(稍后的一行覆盖较早的一行)
I have a particular need for git to treat most file extensions as binary except a few extensions.
I'd like to treat all file extensions as binary, .pdf .doc .xls etc., except plain text files such as .txt .rb .py etc.
I've tried configuring .gitattributes like below to see how this might work:
# cat .gitattributes
* binary
*.txt text
I thought perhaps the order in the configuration file would matter but it doesn't appear to. With the above configuration all files are still treated as binary.
Is there a way to configure .gitattributes or git any other way to treat all files one way, as binary, except for a few exceptions?
Update 1:
I tried the .gitattributes described below. It works!
# 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
Update 2:
I believe crlf and text are the same i.e. the two below configurations for .gitattributes are the same:
# cat .gitattributes
*.txt crlf diff
* binary
# cat .gitattributes
*.txt text diff
* binary
binary
is a macro setting the attribute crlf and diff (actually here unsetting them)
See "USING ATTRIBUTE MACROS" from the .gitattribute
man page.
Once an attribute is set or unset, if cannot be changed by a subsequent rule.
So you could try:
* binary
*.txt crlf diff
That way, crlf
and diff
being set for *.txt
files, they won't be unset by the binary macro for those same *.txt
files, while they will be unset for all the other files.
From the 2009 commit b9d14ff, those rules should go:
- from the more general ones
- to the more specific ones.
("a later line overrides an earlier line")
这篇关于git的.gitattributes可以将所有文件视为二进制文件,只有少数例外情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!