git diff 命令比较文件的不同,即比较文件在暂存区和工作区的差异。
git diff 命令显示已写入暂存区和已经被修改但尚未写入暂存区文件对区别。
git diff 有两个主要的应用场景。
- 尚未缓存的改动:git diff
- 查看已缓存的改动: git diff --cached
- 查看已缓存的与未缓存的所有改动:git diff HEAD
- 显示摘要而非整个 diff:git diff --stat
============================================================
此仓库里面的文件是最新clone下来的,工作区与暂存区的一样:
git diff命令:显示工作区与暂存区没有区别
====================================================
此时我在工作区里面的5.txt里面增加内容,然后再操作:
=====================================================
我把修改好的5.txt进行git add . 然后再执行git diff命令,就发现没有区别了:
===================================================
5.txt文件已经被提交了,现在我再更改工作区的5.txt文件,然后再执行git diff命令:
===================================================================================
显示暂存区和工作区的差异:
$ git diff [file]
======================================================
显示暂存区和上一次提交(commit)的差异:
$ git diff --cached [file] 或 $ git diff --staged [file]
=============================================================
看已缓存的与未缓存的所有改动:git diff HEAD
===================================================
显示两次提交之间的差异:
$ git diff [first-branch]...[second-branch]
==========================================================
- 显示摘要而非整个 diff:git diff --stat
==========================================================