git HEAD 和当前项目状态的区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3293607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between git HEAD and the current project state?
提问by never_had_a_name
I quote a git tutorial:
我引用了一个 git 教程:
git diff shows the diff between HEAD and the current project state
I wonder what that means. Isn't the HEAD the current active project?
我想知道那是什么意思。HEAD 不是当前活动的项目吗?
Thanks
谢谢
回答by VonC
From "Specifying revisions"
来自“指定修订版”
HEAD
names the commit on which you based the changes in the working tree.
HEAD
命名您基于工作树中的更改的提交。
There are other heads (FETCH_HEAD
, ORIG_HEAD
and MERGE_HEAD
). See Jefromi's answerfor more.
还有其他头 ( FETCH_HEAD
,ORIG_HEAD
和MERGE_HEAD
)。有关更多信息,请参阅Jefromi 的回答。
The thing is, by default git diff
actually shows the differences between "the current state of your project" (i.e. your files on your working tree) and the index(not HEAD).
In other words, the differences are what you couldtell git to further add to the index but you still haven't.
问题是,默认情况下git diff
实际上显示了“项目的当前状态”(即工作树上的文件)和索引(不是 HEAD)之间的差异。
换句话说,不同之处在于您可以告诉 git 进一步添加到索引中,但您仍然没有。
if you do git diff --cached
, thenit will compare the index with HEAD.
如果你这样做git diff --cached
,那么它会将索引与 HEAD 进行比较。
See git book for more (archive link):
有关更多信息,请参阅git book(存档链接):
A common use is to simply run
$ git diff
which will show you changes in the working directory that are not yet staged for the next commit. If you want to see what is staged for the next commit, you can run
$ git diff --cached
which will show you the difference between the index and your last commit; what you would be committing if you run "git commit" without the "-a" option. (In Git versions 1.6.1 and later, you can also use
git diff --staged
which may be easier to remember.) Lastly, you can run$ git diff HEAD
which shows changes in the working directory since your last commit; what you would be committing if you run "git commit -a".
一个常见的用途是简单地运行
$ git diff
这将显示工作目录中尚未为下一次提交暂存的更改。如果您想查看为下一次提交暂存的内容,您可以运行
$ git diff --cached
这将显示索引和上次提交之间的差异;如果您在没有“-a”选项的情况下运行“git commit”,您将提交什么。(在 Git 版本 1.6.1 及更高版本中,您还可以使用
git diff --staged
它可能更容易记住。)最后,您可以运行$ git diff HEAD
显示自上次提交以来工作目录中的更改;如果您运行“git commit -a”,您将提交什么。
See also 365git: Getting a diff between the working tree and other commits:
回答by chimeracoder
git diff
is for showing the uncommitted changes (ie, the work that you have done but have not yet committed to the current project).
git diff
用于显示未提交的更改(即您已完成但尚未提交到当前项目的工作)。
Here's a full explanation: http://git-scm.com/docs/git-diff
这是一个完整的解释:http: //git-scm.com/docs/git-diff