git diff

Comparing Changes with git diff

With no arguments git diff compares the working tree with the index: what you changed but have not staged. Add an example environment file, document it in the README, and compare:

Diffing the working tree, then the staging areaShell
printf 'PORT=3000\nPGHOST=localhost\nPGPASSWORD=change-me\n' > .env.example
cat >> README.md <<'EOF'
## Local configuration
Copy `.env.example` to `.env` and edit it. Git ignores `.env`.
EOF
git status --short
git diff
git add README.md
git diff --staged --stat
Output
 M README.md
?? .env.example
diff --git a/README.md b/README.md
index b2522eb..0164f73 100644
--- a/README.md
+++ b/README.md
@@ -29,3 +29,7 @@ The schema and the six-book seed catalog (`db/schema.sql`,
 
 `PORT` (default `3000`), and `PGHOST`, `PGPORT`, `PGUSER`,
 `PGPASSWORD`, `PGDATABASE` (defaults match `docker-compose.yml`).
+
+## Local configuration
+
+Copy `.env.example` to `.env` and edit it. Git ignores `.env`.
 README.md | 4 ++++
 1 file changed, 4 insertions(+)

The index line names the old and new blobs, and the hunk header @@ -29,3 +29,7 @@ says three lines from line 29 became seven; lines start with - (removed), + (added) or a space (context). .env.example is absent: Git 1,932 never diffs untracked files. --staged (alias --cached) compares the index with HEAD, the commit you are about to make. git diff A B compares two commits, and --word-diff marks changes inside lines.