Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

git - Make github use .gitattributes "binary" attribute

In my project, I need to track some files into version control, csv files in this example. But the files contain a considerable amount of lines and cause Github to occasionally supress files that must go through code review for pull requests to be accepted and merged.

I tried using .gitattributes to mark such files either as binaries or just to not being diplayed in the diff using:

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

one at a time, as well as combining them. This works perfectly on diffs on the terminal:

$ 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

but when the branch is pushed to Github and compared against another branch, Github ignores these attributes and displays the file diff as text, though .gitattributes is "customizing" the way the diff should be displayed:

github diff view

Is there any way to force the diff in Github consider the attributes in .gitattributes to customize the behavior of the diff so that the diff of the indicated files is supressed?

Thanks in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I had asked the similar question to Github that

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?

The reply from them was

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.

So, for now Github does not support .gitattributes file to suppress any diff.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...