开发者

Difference between git HEAD and the current project state?

开发者 https://www.devze.com 2023-01-08 07:26 出处:网络
I quote a git tutorial: git diff shows the diff between HE开发者_StackOverflow中文版AD and the current project state

I quote a git tutorial:

git diff shows the diff between HE开发者_StackOverflow中文版AD 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:

Difference between git HEAD and the current project state?


git diff is for showing the uncommitted changes (ie, the work that you have done but have not yet committed to the current project).

Here's a full explanation: http://git-scm.com/docs/git-diff

0

精彩评论

暂无评论...
验证码 换一张
取 消