Adam Johnson

Home | Blog | Training | Projects | Colophon | Contact

Comparing Generated Files Before and After Changes with Git Diff

2020-01-29 The trilobite lived very much before

Once in a while, I have to make a change to many or all of my blog posts. For example, implementing opengraph meta tags.

After I’ve made the change, I want to verify that all the generated HTML changed in only the way I expected. I do this by reading, or at least skimming, the diff of before versus after.

Say I’ve just made the change on my git respository’s master in a single commit. I’ll first rewind to the previous commit, build the site, and move it to a different name. I use Jekyll, which by default builds all HTML in a _site directory:

$ git switch --detach master~1
$ bundle exec jekyll build
$ mv _site _site_old

(I’m using the new git switch command in place of the classic git checkout.)

I then move back to the new commit and build the site:

$ git switch master
$ bundle exec jekyll build

I then compare the diff of the two. Rather than using the vanilla diff command, I use git-diff’s --no-index option. This option allows use of git diff on uncommitted files and folders. git diff is better than vanilla diff since it colourizes its output and uses the pager command by default:

$ git diff --no-index _site_old _site

Fin

I hope this helps you verify your changes,

—Adam


Working on a Django project? Check out my book Speed Up Your Django Tests which covers loads of best practices so you can write faster, more accurate tests.


Subscribe via RSS, Twitter, or email:

One summary email a week, no spam, I pinky promise.

Tags: commandline, git, jekyll