git diff - ghdrako/doc_snipets GitHub Wiki
git diff [--options] <commit> <commit> [--] [<path>...]
git diff <ID1>..<ID2> -- <filename> # see all changes to the file between the two commits on a commit-by-commit basis,
git diff <ID1> <ID2> -- <filename> # show difference only in specyfic file
git diff <ID1> <ID2> --name-only # # get only files names
Example:
$ git diff HEAD^^ HEAD main.c
$ git diff HEAD^^..HEAD -- main.c
$ git diff HEAD~2 HEAD -- main.c
$ git diff HEAD~1..HEAD~3
$ git diff oldCommit..newCommit
$ git diff oldCommit newCommit
$ git diff k73ud dj374 --name-only # get only files names
$ git diff k73ud dj374 > my.patch
$ git apply my.patch
$ git diff # show difference working copy and staging area
$ git diff --staged # Staging area and the latest commit
$ git diff 4ac0a6733 # working copy and commit 4ac0a6733
$ git diff 4ac0a6733 HEAD # Commit 4ac0a6733 and the latest commit
$ git log -p # show the changes introduced with each commit
$ git log -p --reverse old_hash..new_hash
Since Git 2.19, you can simply use:
git range-diff rev1...rev2 - compare two commit trees, starting by their common ancestor
or
git range-diff rev1~..rev1 rev2~..rev2 - compare of changes introduced by 2 given commits
You can also compare two different files in two different revisions, like this:
git diff <revision_1>:<file_1> <revision_2>:<file_2>