Difference between git HEAD and the current project state?

Git

Git Problem Overview


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

Git Solutions


Solution 1 - Git

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:

http://images.abizern.org.s3.amazonaws.com/365git/Feb11/Git%20Diff%202.png

Solution 2 - Git

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionnever_had_a_nameView Question on Stackoverflow
Solution 1 - GitVonCView Answer on Stackoverflow
Solution 2 - GitchimeracoderView Answer on Stackoverflow