git-diff - Show changes between commits, commit and working tree, etc
git diff [options] [<commit>] [--] [<path>…]
git diff [options] --cached [<commit>] [--] [<path>…]
git diff [options] <commit> <commit> [--] [<path>…]
git diff [options] <blob> <blob>
git diff [options] [--no-index] [--] <path> <path>
1.比较工作区和暂存区
git diff # 工作区和暂存区的差异
2.比较暂存区和仓库区
git diff --staged # 比较暂存区和仓库区上次提交的差别
git diff --cache # --cache和staged是同义词
3.比较工作区和仓库区的区别
git diff HEAD
4.比较commit
git diff <id1><id2> # 比较两次提交之间的差异
git diff <id1:file> <id2:file> # 比较文件在id1版本和id2版本之间的差异
5.比较branch
git diff <branch1> # 查看工作区和指定分支的差异
git diff <branch1> <branch2> # 在两个分支之间比较
6.比较remote和local
git fetch
git diff origin/master
git diff 默认是和工作区比较
git diff <file> # 比较当前文件和暂存区文件差异
git diff --staged <file> #比较暂存区文件和仓库区文件的差异
# 以上四个各方法都是以仓库区为标准的
git diff HEAD # 比较工作区和HEAD指针指向的仓库区的差异
git diff <HEAD:file> <HEAD~n:file> #比较文件在HEAD和HEAD~n版本之间的差异
git diff <branch1:file> <branch2:file> # 比较文件在b1分支和b2分支之间的关系
git diff --stat # 仅仅比较统计信息
参考文献:
https://git-scm.com/docs/git-diff
http://www.findme.wang/share/detail/id/327.html