git diff HEAD与git diff --staged有什么区别? [英] What is the difference between git diff HEAD vs. git diff --staged?

查看:285
本文介绍了git diff HEAD与git diff --staged有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

git diff HEADgit diff --staged有什么区别?我都尝试过,但是都给出相同的输出.

What is the difference between git diff HEAD and git diff --staged? I tried both but both give the same output.

推荐答案

假设此输出为git status:

$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   y
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   x
#

如您所见,已经修改了一个文件,但未准备好提交该文件,并且添加了一个准备好提交的新文件.

As you see, there is one file modified but not staged for commit, and a new file added that is ready to be committed.

git diff --staged仅显示对暂存"区域中文件的更改.

git diff --staged will only show changes to files in the "staged" area.

git diff HEAD将显示对跟踪文件的所有更改.如果您已准备好所有更改以进行提交,那么这两个命令将输出相同的内容.

git diff HEAD will show all changes to tracked files. If you have all changes staged for commit, then both commands will output the same.

这篇关于git diff HEAD与git diff --staged有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆