This post goes over how to inspect changes with git diff
.
Prerequisites
Given the following:
echo 'Hello, world' > file.txt && git add . && git commit -m 'add file'
The text world
is replaced with Mark
:
sed -i.bak 's/world/Mark/' file.txt
git diff
Inspect the changes with git diff
:
git diff
-Hello, world
+Hello, Mark
Additionally, --word-diff
is useful for side-by-side comparisons per line:
git diff --word-diff
Hello, [-world-]{+Mark+}
If you stage the changes for commit:
git add file.txt
You can inspect the diff again with --cached
or --staged
:
git diff --cached
You can even compare branches:
git diff master..dev
As well as revisions:
git diff af5626b..6fd855f