gpt4 book ai didi

git - 让 github 使用 .gitattributes "binary"属性

转载 作者:IT王子 更新时间:2023-10-29 00:36:16 24 4
gpt4 key购买 nike

在我的项目中,我需要将一些文件跟踪到版本控制中,本例中为 csv 文件。但是这些文件包含相当多的行,导致 Github 偶尔会抑制必须通过代码审查才能接受和 merge pull 请求的文件。

我尝试使用 .gitattributes 将此类文件标记为二进制文件或只是为了不在 diff 中使用:

+*.csv -diff
+*.csv -merge
+*.csv binary

一次一个,以及组合它们。这对终端上的差异非常有效:

$ git diff HEAD^
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..8a86f80
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+*.csv -diff -merge binary
diff --git a/AssetsImportCompleteSample.csv b/AssetsImportCompleteSample.csv
new file mode 100644
index 0000000..5b20a6e
Binary files /dev/null and b/AssetsImportCompleteSample.csv differ

但是当分支被推送到 Github 并与另一个分支进行比较时,Github 忽略这些属性并将文件差异显示为文本,尽管 .gitattributes 正在“自定义”差异的显示方式:

github diff view

有什么方法可以强制 Github 中的差异考虑 .gitattributes 中的属性来自定义差异的行为,以便抑制指定文件的差异?

提前致谢!

最佳答案

我在Github上问过类似的问题

Is there anyway to suppress using .gitattributes the diff of machine generated codes which needs to be versioned and cannot be ignored by using .gitignore file?

他们的回复是

GitHub doesn't use .gitattributes files for choosing which files to show in a diff, so it's not possible to get around this that way.

The only current way to suppress certain files in a diff, is to have the classified as "generated" by Linguist:

https://github.com/github/linguist#generated-file-detection

If you want to do that, you would need to check out the details of how Linguist classifies files as "generated" and make sure that your files qualify. I cannot say whether this is doable for the specific files which you are interested in suppressing from the diff.

因此,目前 Github 不支持 .gitattributes 文件来抑制任何差异。

关于git - 让 github 使用 .gitattributes "binary"属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24212291/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com