Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make github use .gitattributes "binary" attribute

Tags:

git

github

diff

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!

like image 720
Gerard Avatar asked Jun 13 '14 19:06

Gerard


Video Answer


2 Answers

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.

like image 189
Ramsharan Avatar answered Oct 05 '22 21:10

Ramsharan


2020 answer

Generated files like minified JavaScript and compiled CoffeeScript can be detected and excluded from language stats. As an added bonus, unlike vendored and documentation files, these files are suppressed in diffs. generated.rb lists common generated paths and excludes them from the language statistics of your repository.

Use the linguist-generated attribute to mark or unmark paths as generated.

Add into .gitattributes

myfile.csv linguist-generated
like image 40
askaroni Avatar answered Oct 05 '22 21:10

askaroni