Last week one endpoint in production started returning 500s. The same code on my laptop worked fine. Same database, same queue, same deploy. The only thing that wasn't the same, as far as I could tell, was configuration.

I pulled the env file off the server (/etc/myapp/.env) and put it next to my local .env.development. 118 lines each. I read them side by side for about forty seconds, and my eyes started gliding. That's the thing about config drift: every line looks boring, and the one broken line looks exactly like the other 117.

So I stopped reading and started diffing. Here are the three ways I now compare config files, from the most manual to the one I reach for first.

Method 1: a small Python script

Python 3.11.1, standard library only. The trick is to strip comments and blank lines first, otherwise they bury the real changes in noise:

# env_diff.py — compare two env files, ignoring comments and blank lines import difflib, sys def load(path): with open(path, encoding="utf-8") as f: lines = f.read().splitlines() return [l for l in lines if l.strip() and not l.lstrip().startswith("#")] a, b = load(sys.argv[1]), load(sys.argv[2]) out = list(difflib.unified_diff(a, b, fromfile=sys.argv[1], tofile=sys.argv[2], lineterm="")) print("\n".join(out) if out else "no meaningful differences") 

Running it pointed at the problem in one screen:

--- .env.development +++ .env.production @@ -41 +41 @@ -MAX_UPLOAD_MB=8 +MAX_UPLOAD_MB=2 

The upload limit on prod was 2 MB. The failing endpoint accepts a 3 MB file upload, so the server answered with a 413 that our error wrapper reported as a generic 500. One variable. Eight seconds of diffing versus twenty minutes of careful reading.

Method 2: git diff outside a repository

When I don't want to write even ten lines, git diff --no-index works on any two files, repo or not. The git diff documentation describes the flag as "compare the given paths, outside the working tree", which is exactly the config-file case:

git diff --no-index --unified=1 .env.development .env.production 

You get colors, context lines, and -/+ prefixes straight in the terminal. Two things worth knowing before you rely on it: it exits with code 1 whenever the files differ, so don't drop it into a set -e CI script without appending || true; and if git isn't installed on the box you're SSH'd into, the GNU diffutils manual covers the plain diff -u file1 file2, which produces the same patch-format output minus the colors.

Method 3: in the browser, no script at all

For one-off comparisons on machines I don't control (a client's server, a borrowed laptop), I paste both files into this browser-based text diff tool. It highlights added and removed lines side by side, and everything runs locally in the tab, so the config never leaves the machine. That last part matters more than it sounds, because env files usually contain tokens or database URLs.

I use the same line-by-line diff checker as a second pair of eyes when logs are involved: paste the request line from a working run next to the one from the failing run, and the changed field jumps out immediately instead of hiding in a wall of JSON.

Three traps I hit along the way

Trap 1: invisible quotes and trailing spaces. A teammate "cleaned up" the prod file and wrapped some values in quotes. The diff came back as:

-LOG_LEVEL=debug +LOG_LEVEL="debug" 

It looks like two real changes, but the runtime value is identical in most parsers. Worse, the first line has a trailing space you can't see in a normal terminal. cat -A exposes it as LOG_LEVEL=debug $, where the $ marks the end of line. Don't chase differences that don't change behavior.

Trap 2: multiline values shift every line below them. One prod file embeds a TLS private key across 22 lines. A single-line change above the key shifts the whole block, and plain diff then reports 23 changes instead of 1. When that happens, I diff the keys only and inspect values separately:

grep -o '^[A-Za-z_]*=' .env.development | sort > /tmp/keys_dev.txt grep -o '^[A-Za-z_]*=' .env.production | sort > /tmp/keys_prod.txt diff /tmp/keys_dev.txt /tmp/keys_prod.txt 

Missing or renamed variables jump out immediately, with no key-block noise in the way.

Trap 3: cloud diff sites upload your text. Most "compare two texts" websites POST the pasted content to their servers for processing. With env files, that's a credentials leak waiting to happen. A client-side tool that never uploads is the only kind I'll paste real config into, and if the file is genuinely sensitive, the Python method on the machine where the file lives is safer still.

Which method when

Situation What I use
Repeated audits, part of a release checklist Python script, output piped into the CI log
Quick terminal check on any machine git diff --no-index -U1
Borrowed machine, no tooling installed browser-based text diff

The 500 stayed live for two hours because reading carefully felt cheaper than running a diff. It isn't. Env comparison is now the first thing I check on a config-dependent failure, not the last.

More free browser-based utilities at utilvy.com.