Git diff

Given the following:

$ echo 'Hello, world' > file.txt
$ git add .
$ git commit -m 'Add file'

And replacing world with Mark:

$ sed -i.bak 's/world/Mark/' file.txt

git diff

You can inspect the changes with git diff:

$ git diff
-Hello, world
+Hello, Mark

Additionally, the --word-diff option is helpful 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

And you can even compare branches:

$ git diff

As well as revisions:

$ git diff af5626b..6fd855f

Check out the documentation for more information.

Please support this site and join our Discord!