小白教程
所有教程
关于
Search
172.70.126.50
172.70.126.50
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Git diff”的源代码
本页内容
上一节:
Git_status
下一节:
Git_commit
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:git diff}}[[Category:git basic operations|5]] = git diff 命令 = [[git basic operations|Git 基本操作]] git diff 命令比较文件的不同,即比较文件在暂存区和工作区的差异。 git diff 命令显示已写入暂存区和已经被修改但尚未写入暂存区文件的区别。 git diff 有两个主要的应用场景。 * 尚未缓存的改动:'''git diff''' * 查看已缓存的改动: '''git diff --cached''' * 查看已缓存的与未缓存的所有改动:'''git diff HEAD''' * 显示摘要而非整个 diff:'''git diff --stat''' 显示暂存区和工作区的差异: <sample title="" desc="" lang="shell" hererun="1"> $ git diff [file] </sample> 显示暂存区和上一次提交(commit)的差异: <sample title="" desc="" lang="shell" hererun="1"> $ git diff --cached [file] 或 $ git diff --staged [file] </sample> 显示两次提交之间的差异: <sample title="" desc="" lang="shell" hererun="1"> $ git diff [first-branch]...[second-branch] </sample> 在 hello.php 文件中输入以下内容: <sample title="" desc="" lang="shell" hererun="1"> <?php echo '小白教程:www.xiaobai.wang'; ?> </sample> 使用 git status 查看状态: <sample title="" desc="" lang="shell" hererun="1"> $ git status -s A README AM hello.php $ git diff diff --git a/hello.php b/hello.php index e69de29..69b5711 100644 --- a/hello.php +++ b/hello.php @@ -0,0 +1,3 @@ +<?php +echo '小白教程:www.xiaobai.wang'; +?> </sample> git status 显示你上次提交更新后的更改或者写入缓存的改动, 而 git diff 一行一行地显示这些改动具体是啥。 接下来我们来查看下 git diff --cached 的执行效果: <sample title="" desc="" lang="shell" hererun="1"> $ git add hello.php $ git status -s A README A hello.php $ git diff --cached diff --git a/README b/README new file mode 100644 index 0000000..8f87495 --- /dev/null +++ b/README @@ -0,0 +1 @@ +# xiaoBai Git 测试 diff --git a/hello.php b/hello.php new file mode 100644 index 0000000..69b5711 --- /dev/null +++ b/hello.php @@ -0,0 +1,3 @@ +<?php +echo '小白教程:www.xiaobai.wang'; +?> </sample> [[git basic operations|Git 基本操作]]
返回至“
Git diff
”。
上一节:
Git_status
下一节:
Git_commit