简体   繁体   English

git diff-将索引与HEAD比较? 暂存区和HEAD呢?

[英]git diff - compares index to HEAD? What about staging area and HEAD?

So I have been confused about this for a while. 所以有一段时间我对此感到困惑。

Does git diff , compare the index to HEAD by default? git diff是否默认将indexHEAD比较? Or the staging area with HEAD ? 还是HEADstaging area

Assuming git diff compares the index with HEAD, how would I run git diff between staging and HEAD instead of the index and HEAD? 假设git diff将索引与HEAD进行比较,我将如何在登台和HEAD之间而不是索引和HEAD之间运行git diff

what? 什么? First staging area and index are the same. 第一staging areaindex相同。 Then, git diff compares HEAD+index (so to speak) with your working tree. 然后,git diff将HEAD + index(可以这么说)与您的工作树进行比较。

To compare working directory with staging / index use: 要将工作目录暂存/索引进行比较,请使用:

git diff [--options] [--] [<path>…​]

This answers the question What I have changed in files in this repo? 这回答了这个仓库中我对文件所做的更改?

To compare staging / index with HEAD (<commit> defaults to HEAD ) use: 要将登台/索引HEAD (<commit>默认为HEAD )进行比较,请使用:

git diff [--options] --cached [<commit>] [--] [<path>…​]

--cached can be switched with --staged if it easier for you to remember. 如果更易于记忆,可以使用--staged切换--cached In documentation index, staging and cached are all used to mean the same thing. 在文档索引中,暂存和缓存均用于表示同一件事。

This answers the question What my next commit will look like? 这回答了我的下一次提交将是什么样的问题

Extra 额外
To compare working directory with HEAD use: 要将工作目录HEAD进行比较,请使用:

git diff $(git rev-parse --short HEAD) [--] [<path>…​]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM