Skip to content
Git Basics: Review Small Prose Edits with Word Diffs

Git Basics: Review Small Prose Edits with Word Diffs

October 29, 2026

A single-word edit can be hard to spot in a long removed-and-added line. This local example changes one retry count and displays the edit inline without terminal color.

Prepare a scratch directory

Tested on Linux with Git 2.52.0 and GNU Bash 5.2.37. You need Bash, Git, a text editor, and standard mktemp, rm, rmdir, cat, head, wc, and sed utilities. Run from an ordinary shell without repository-selection variables such as GIT_DIR, GIT_WORK_TREE, or GIT_INDEX_FILE set. The script isolates global and system Git configuration and uses fictional identities only in its temporary repository.

Keep the same terminal open. Stop if setup fails, before saving the source:

start_dir="$PWD"
work_dir="$(mktemp -d)" || exit 1
cd -- "$work_dir" || exit 1

Run the example

Save this as demonstrate-word-diff.sh:

#!/usr/bin/env bash
set -euo pipefail
export LC_ALL=C
fixture_dir="$(mktemp -d)"
trap 'rm -rf -- "$fixture_dir"' EXIT
export GIT_CONFIG_NOSYSTEM=1
export GIT_CONFIG_GLOBAL=/dev/null
export GIT_AUTHOR_NAME='Example Author'
export GIT_AUTHOR_EMAIL='author@example.invalid'
export GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"
export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
export GIT_AUTHOR_DATE='2026-10-29T00:00:00+00:00'
export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
git init -q --object-format=sha1 -b main "$fixture_dir/repo"
cd -- "$fixture_dir/repo"
git config commit.gpgsign false
git config core.hooksPath /dev/null
printf 'The service retries three times before stopping.\n' > guide.txt
git add guide.txt
git commit -qm 'Write retry guidance'
printf 'The service retries five times before stopping.\n' > guide.txt
git diff --no-color --word-diff=plain -- guide.txt
test "$(git show HEAD:guide.txt)" = 'The service retries three times before stopping.'
test "$(cat guide.txt)" = 'The service retries five times before stopping.'

Run it:

bash demonstrate-word-diff.sh

Observed output:

diff --git a/guide.txt b/guide.txt
index bf2642a..6e32484 100644
--- a/guide.txt
+++ b/guide.txt
@@ -1 +1 @@
The service retries [-three-]{+five+} times before stopping.

Read the result

The unchanged words stay visible around [-three-]{+five+}. The markers identify removed and added text. The assertions verify that the committed sentence still says three while the working file says five. No new commit is created for the edit.

Apply it carefully

This invocation compares the working file with the index; add --cached to inspect staged edits instead. Plain word-diff markers are not escaped when the input already contains them, so they can be ambiguous. Whitespace normally separates words. Use an ordinary unified diff as well when exact spacing or a patch suitable for application matters.

The official Git reference documents these options. The script creates and removes only its own temporary fixture; it does not contact a remote or change your existing repository.

Clean up

Remove the saved script, return to the starting directory, and remove the empty practice directory:

rm -- demonstrate-word-diff.sh
cd -- "$start_dir" || exit 1
rmdir -- "$work_dir"
unset start_dir work_dir

If the directory is not empty, inspect its remaining files rather than deleting unknown content.

Acknowledgements

This post was created with assistance from AI.

Last updated on