Automatically Collapse Generated Files in GitHub Diffs
Not too long ago we introduced Pipe it Down, a Chrome extension to help deal with GitHub pull request diffs with lots of files. The major pain point it addresses for us is dealing with large files automatically generated by Unity. These files rarely get reviewed by a human, but we had to scan through them anyway in order to get to the source files we care about. Being able to collapse those files has helped tremendously.
If you haven't noticed yet, there's now a little chevron in the corner of each file in a GitHub diff that allows you collapse/expand that file.
That's right, the functionality Pipe it Down provides is now a part of GitHub itself! It even works in diffs that aren't a part of a pull request, e.g. commit and compare views.
If you're working with lots of large diffs, manually collapsing files over and over gets quite onerous. There's actually a solution for this too! GitHub uses Linguist to compute stats about your files, ignore files that are vendored, and even to suppress files that are generated automatically. It does most of this without you taking any action, but you can configure it to treat files of your choosing in a certain way.
You can do this configuration via the .gitattributes file. In
general, the format of this file is <file-pattern> <attribute>
. In our Unity
example, there's a handful of files that are automatically generated, so we
created a .gitattributes with the following:
*.asset linguist-generated
*.mat linguist-generated
*.meta linguist-generated
*.prefab linguist-generated
*.unity linguist-generated
This tells Linguist that all .asset, .mat, .meta, .prefab, and .unity files should be treated as generated. If we look at a diff with those in place, we see diffs for those files are not displayed and take up significantly less space. If we do need to see the diff, we can click through to have it loaded.
We are very excited these features are available and look forward to having better reviewing experiences because of them. They go beyond what Pipe it Down could have provided, so it will not be receiving updates going forward. It was a short lived tool, but it served a noble cause and we'll remember it fondly.