Make github use .gitattributes “binary” attribute

久未见 提交于 2019-12-09 04:40:41

问题


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:

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!


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/24212291/make-github-use-gitattributes-binary-attribute

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!