git diff 命令用于显示提交和工作树之间的更改。
01 git diff
🌟 git diff 后面如果不带任何的参数、文件名、提交 id 等,则 👇👇👇
02 git diff HEAD
HEAD:最新一次 commit; HEAD^:上次提交; HEAD~n:上 n 次提交;
🌟 git diff HEAD 请看下面!
03 git diff one two
-
git diff <commit> :若后面只带有一个 commit,则显示的是 HEAD 与 commit 的差异 -
git diff <commit_1> <commit_2> :若后面带有两个 commit,则显示的是 commit_1 与 commit_2 的差异 -
git diff <branch> :若后面只带有一个 branch,则显示的是当前分支与 branch 分支的差异 -
git diff <branch_1> <branch_2> :若后面带有两个 branch,则显示的是 branch_1 分支与 branch_2 分支的差异
04 git diff --cached
--staged 是 --cached 的同义词:git diff --cached === git diff --staged
🌟 git diff --cached :若不提供 commit,默认为 git diff --cached HEAD ,则显示的是暂存区文件与 Git 仓库中文件的差异。
注意:如果 HEAD 不存在,且没有给 commit ,则会显示所有阶段性更改。
05 git diff --stat
?🌟 git diff --stat :用于显示摘要。若命令后不带任何的参数等,则查询的是当前工作区与 Git 仓库的详细更改。
打印展示如下:
$ git diff --stat
a.js | 4 +++-
b.js | 4 +++-
2 files changed, 6 insertions(+), 2 deletions(-)
?
|