git HEAD和当前项目状态之间的区别? [英] Difference between git HEAD and the current project state?

查看:111
本文介绍了git HEAD和当前项目状态之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  git diff显示HEAD和当前项目状态之间的差异

我想知道这意味着什么。是不是HEAD当前的活动项目?



谢谢

指定修订


HEAD 命名您在工作树中基于更改的提交。

还有其他元首( FETCH_HEAD ORIG_HEAD MERGE_HEAD )。详情请参阅 Jefromi的回答



事情是,默认情况下 git diff 实际上显示了你项目的当前状态(即你工作中的文件)树)和索引(不是HEAD)。
换句话说,不同之处在于你可以告诉git进一步添加到索引中如果你使用 git diff --cached ,那么你仍然没有。

然后它会将索引与HEAD进行比较。 git book for more(存档链接)


常见用法是简单地运行

  $ git diff 

这会显示工作目录中尚未为ne执行的更改xt提交。如果你想看看下一次提交的内容,你可以运行

  $ git diff --cached 

它会告诉你索引与上次提交之间的区别;如果在没有-a选项的情况下运行git commit,你会提交什么。 (在Git版本1.6.1和更高版本中,您也可以使用 git diff --staged 这可能会更容易记住)。最后,您可以运行

  $ git diff HEAD 

它显示自上次提交以来工作目录中的更改;如果你运行git commit -a,你会提交什么。

另见 rel =noreferrer> 365git:在工作树和其他提交之间获取差异




I quote a git tutorial:

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?

Thanks

解决方案

From "Specifying revisions"

HEAD names the commit on which you based the changes in the working tree.

There are other heads (FETCH_HEAD, ORIG_HEAD and MERGE_HEAD). See Jefromi's answer for more.

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 could tell git to further add to the index but you still haven't.

if you do git diff --cached, then it will compare the index with HEAD.

See git book for more (archive link):

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".

See also 365git: Getting a diff between the working tree and other commits:

这篇关于git HEAD和当前项目状态之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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