Posted about 1 month ago. Visible to the public.

Git: Parsing large diffs as a human

I just finished migrating a project from the Asset Pipeline to Webpacker, this is what my diff to master looks like:

5.825 files changed, 44.805 insertions(+), 529.948 deletions(-)
warning: inexact rename detection was skipped due to too many files.
warning: you may want to set your diff.renameLimit variable to at least 5134 and retry the command.

There is no way me or my peer reviewer is able to parse 500k+ lines of code. Fortunately, git has some handy diff options ready:

option comment
--color-moved=dimmed_zebra Highlight only changes in renamed files
--find-renames=X% Default: 50%. If not all renames are matched, use a smaller amount.
--diff-algorithm Try out different algorithms if the diff doesn't look right
--no-color-moved-ws Hides white-space changes for moved files
--diff-filter=X Restrict diff to: Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R), Unknown (X) files

To tackle the rename limit mentioned above, update the local or global git configuration.

git config diff.renameLimit 9999

Furthermore, I encourage you to further split the diff into smaller chunks:

  • By file extension (e.g.: first review your Ruby code, then JS, then the rest)
  • By excluding directories (e.g.: handle application and vendor code separately)

Overall I ended up splitting up my code into these (human readable) chunks:

git diff master --color-moved=dimmed_zebra --find-renames=25% '*.sass' ':!vendor' git diff master --color-moved=dimmed_zebra --find-renames=25% '*.coffee' ':!vendor' git diff master --color-moved=dimmed_zebra --find-renames=25% '*.js' ':!vendor' git diff master --color-moved=dimmed_zebra --find-renames=25% '*.haml' ':!vendor' git diff master --color-moved=dimmed_zebra --find-renames=25% '*.rb' ':!vendor' git diff master --color-moved=dimmed_zebra --find-renames=25% ':!*.coffee' ':!*.sass' ':!*.js' ':!*.haml' ':!*.rb' ':!vendor' git diff master --color-moved=dimmed_zebra --find-renames=25% vendor/

Once an application no longer requires constant development, it needs periodic maintenance for stable and secure operation. makandra offers monthly maintenance contracts that let you focus on your business while we make sure the lights stay on.

Owner of this card:

Michael Leimstädtner
Last edit:
about 1 month ago
by Michael Leimstädtner
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Michael Leimstädtner to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more