Fetching contributors…
Cannot retrieve contributors at this time
65 lines (46 sloc) 1.06 KB
layout title date excerpt categories
Git diff
2017-07-27 22:38:05 -4000
Inspect changes with git diff.
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.