---
title: Automatically Collapse Generated Files in GitHub Diffs
teaser: 'Large, generated source code files can be a pain to deal with in diffs, but
  we have the tools to combat them.

  '
tags: unity,vr,3d
author: Chris Thorn
published_on: 2017-04-11
---

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.

[Pipe it Down]: https://thoughtbot.com/blog/pipe-it-down-reducing-diff-noise-on-github-pull-requests

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.

![collapsing a file](https://images.thoughtbot.com/blog-vellum-image-uploads/KCh6CdMR3uQaBi4dERsy_collapse.gif)

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.

[Linguist]: https://github.com/github/linguist

You can do this configuration via the [_.gitattributes_][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:

[gitattributes]: https://git-scm.com/docs/gitattributes

```gitattributes
*.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.

![auto collapsed files](https://images.thoughtbot.com/blog-vellum-image-uploads/wCYL48VQF6X8nVKUNaQg_auto-collapse.png)

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.
