Comparing Generated Files Before and After Changes with Git Diff

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


I hope this helps you verify your changes,


Improve your Django develompent experience with my new book.

Subscribe via RSS, Twitter, Mastodon, or email:

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

Tags: , ,