A few answers miss a special case. How to view changes made by the Root Commit as it does not have a parent/ancestor.
Both
git diff <root_commit>^..<root_commit>
and
git diff <root_commit>~..<root_commit>
throw an error.
$git diff 27e521ca73a46b2d3a28568dc49fced81e46aaea~ 27e521ca73a46b2d3a28568dc49fced81e46aaea fatal: ambiguous argument '27e521ca73a46b2d3a28568dc49fced81e46aaea~': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]'
git diff <root_commit>^!
shows diff btw root commit and HEAD. Like so:
$ git diff 27e521ca73a46b2d3a28568dc49fced81e46aaea^! diff --git a/file1.txt b/file1.txt new file mode 100644 index 0000000..80f3f1a --- /dev/null +++ b/file1.txt @@ -0,0 +1,5 @@ +Create the first file. + +Add some placeholder text to first file. + + diff --git a/file2.txt b/file2.txt new file mode 100644 index 0000000..66e494f --- /dev/null +++ b/file2.txt @@ -0,0 +1,6 @@ +This is the second file. + +It has an uncommited commit. + +We use it to demo default `git diff` behaviour. +
(These are changes made by all commits btw my root commit and HEAD).
For Root Commit
I find only
git show --color --pretty=format:%b <root_commit_hash>
works.
Like so:
$ git show --color --pretty=format:%b 27e521ca73a46b2d3a28568dc49fced81e46aaea diff --git a/README b/README new file mode 100644 index 0000000..12a04f0 --- /dev/null +++ b/README @@ -0,0 +1,6 @@ +# git-diff-demo + +This repo documents the demo of the git diff command. +We will have options, and use cases.
(My root commit added only the README)