23

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!

Gerard
  • 9,088
  • 8
  • 37
  • 52

3 Answers3

23

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.

Ramsharan
  • 2,054
  • 2
  • 22
  • 26
  • That's not exactly the same as "GitHub doesn't support using `.gitattributes` to suppress diffs". That's exactly how you're intended to do it in GitHub. Would be much better if they obbey `-diff` or `-merge`, but... that's something. – igorsantos07 Jun 12 '20 at 21:11
3

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
Community
  • 1
  • 1
askaroni
  • 913
  • 5
  • 10
  • that's actually mentioned in the accepted answer, which is just not well worded – igorsantos07 Jun 12 '20 at 21:09
  • Back in 2014 when I originally asked this, using `.gitattributes` was not an option but now it is. Thanks @askaroni for posting an up-to-date answer to this question, hopefully it can be helpful for someone nowadays – Gerard Jun 26 '20 at 17:01
0

Hmm...this was my question as well. I have visual studio .sequencediagrams I update along with my code, and I would prefer they NOT be displayed in my pull request diffs just like word docs aren't. Thought setting .gitattributes to binary would work. Sounds like it's a no go.

Reverting to my previous preference - docs ALL go in their own repository. That way I can control exclusive checkout for just this type of "easier to avoid than to merge" document while maintaining ability to have the documentation open / updating WHILE I develop (which I can't do if I just put them in their own pull request). I don't put them in the SAME pull request because as priorities change, some pull requests get sat on for a while and boom, multiple tips of same document/diagram/etc.

AliceW
  • 41
  • 2