brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: read a small edit in a long line with git diff --word-diff

Git
~/tips/tip-git-diff-word-diff

git diff --word-diff

Shows changes word by word instead of line by line.

Change one word in a long paragraph and git shows the whole line as removed and added. Finding the difference is a game of spot the word.

git diff --word-diff

With this option git still computes the normal line diff, then compares words inside each changed hunk. The default mode, plain, shows removed words as [-old-] and added words as {+new+}. If your terminal does colors, --color-words does the same with colors only, without the brackets.

git diff --color-words
git diff --word-diff-regex=.

A word is a run of non-whitespace by default. With --word-diff-regex=. every character counts as a word, so you see exactly which letters changed. That is nice for a typo in a long URL or a hash.

This fits prose, Markdown and config files with long lines much better than code. A changed word in a README is easy to see. In code, line by line is usually clearer.

The caveat from the docs: it works from the normal line-by-line diff, so the result can be larger than what a dedicated word-diff tool would produce. For the day-to-day it is plenty.

Further reading: git diff documentation, On this site: git diff –staged shows what your commit will contain, On this site: git commit –fixup plus –autosquash keeps your history clean without any editing

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link