Showing difference in Git

git diff command shows difference between commits, commit and working tree, commit and staging area, working tree and staging area, etc.

Note: If you want to show difference in a visible tool, git difftool works for you. It accepts the same options as git diff .

The default difftool used by Git is vimdiff, you can set up your own difftool like Beyond Compare, see

Setting up Beyond Compare as difftool and mergetool in Git

Difference between commits

# Difference between two commits
$ git diff  

# Examples:
# Difference between HEAD's parent and HEAD
$ git diff HEAD~ HEAD

If you just want to show difference for a file, add -- :

# Difference between HEAD's parent and HEAD for index.php
$ git diff HEAD~ HEAD -- ./index.php

Difference between working tree and staging area

In other words, the , the below command show the untagged changes :

# Difference between working tree and staging area
$ git diff

Difference between working tree and commit

# Difference between working tree and commit
$ git diff 

# Examples:

# Difference between working tree and commit specified by '323552e'
$ git diff 323552e

Difference between staging area and commit

# Difference between staging area and commit
$ git diff --cached []

# Examples:

# Difference between staging area and HEAD. In other words, show the changes to be committed
$ git diff --cached

# Difference between staging area and HEAD~
$ git diff --cached HEAD~

More options about git-diff

Ignore whitespace in git-diff

# Ignore all whitespace: use -w or --ignore-all-space
$ git diff -w 

# Ignore whitespace at line end: use --ignore-space-at-eol
$ git diff --ignore-space-at-eol

# Ignore whitespace amount and whitespace at line end: 
# use -b or --ignore-space-change
$ git diff -b

# Ignore blank lines: use --ignore-blank-lines
$ git diff --ignore-blank-lines

Ignore EOF difference in git-diff

To ignore line ending difference (CRLF and LF) , you can use --ignore-cr-at-eol to ignore the CR at line end.

# Ignore CR at line end.
$ git diff --ignore-cr-at-eol

Reference