Debugging Kubernetes

23 Jul 2024

Helpful tips for debugging applications running in k8s

build/k8s.png

Handling multiple errors in Rust iterator adapters

17 Dec 2023

Approaches for handling multiple errors within iterator adapters

build/rust.png

Better FastAPI Background Jobs

29 Aug 2022

A more featureful background task runner for Async apps like FastAPI or Discord bots

build/fastapi_logo.png

Useful Linux Examples

21 Dec 2021

A plethora of helpful tips for working in Linux

build/bash_logo.png
Continue to all blog posts

git diff HEAD vs staged vs local

When using tools like pre-commit (as I’ve discussed in my post on simple CI pipelines) you often end up in the state where it would be handy to review the differences between:

  1. the code you staged for commit (which pre-commit ran its checks against)
  2. the local version of the code after various automations like black have run on the code and created modified versions of the code locally (unstaged)

It’s not particularly obvious how to see the familiar differences between these versions of the code, but you want to see what’s going on if you’re not happy to blindly accept the changes made to your code. If you are, you just git add . to accept all the changes

Using git

If the differences are fairly small and simple, viewing the differences in the command line with git is possible, however this becomes impractical with larger amounts of lines changed

git status -vv

Using pycharm

If you’ve used pycharm for any significant length of time, you’ve probably used the nice functionality to compare differences between commits, or between the HEAD and the local state of the code. It’s not very clear though how to do the same thing between the three existing states HEAD, Staged changes, Unstaged/local changes…

First you need to “Enable staging area” in the git settings of Pycharm.

Then you have two options:

Commit tab

Go to the “Commit” tab (on the left-hand side where “Project” is) and right-click a file > “Compare HEAD, Staged and Local versions”

From a file with changes

Right-click in the editor > “Compare HEAD, Staged and Local versions”