What the diff compares
| Row | Meaning | Typical cause |
|---|---|---|
| + Added | key exists only in B | new feature or service configured in B |
| - Removed | key exists only in A | forgotten variable on a new server |
| ~ Changed | key in both, different value | different credentials, URLs or flags |
| unchanged (count) | same key, same value | shared defaults |
Both files are parsed before comparing: quotes, inline comments, export and line order are ignored, so the diff only shows what a dotenv loader would actually see. To check one file for syntax problems first, use the .env validator.
Comparing environments safely
- Export the current values:
vercel env pull .env.prod --environment=production,heroku config -s > .env.prod, orkubectl get secret app-env -o jsondecoded with the ENV to base64 tool. - Paste staging as A and production as B. Keep mask values on.
- Treat every removed row as a deploy blocker unless you know the key is obsolete.
- Delete the exported file afterwards; it is a full copy of production secrets.
To check only for missing keys against your template, the missing env detector is quicker. To combine files instead of comparing them, use the ENV merger.
Diffing .env files on the command line
# keys only (no values printed): what is in A but not in B, and vice versa
diff <(grep -oE '^[A-Za-z_][A-Za-z0-9_]*' .env.staging | sort -u) \
<(grep -oE '^[A-Za-z_][A-Za-z0-9_]*' .env.production | sort -u)
# git: compare the template between two branches
git diff main..feature -- .env.exampleThe key-only diff is safe for CI logs. Never print full diff output of real .env files in a pipeline: logs are often visible to more people than the secrets are.