views:

108

answers:

4

Hi all,

I presume this is a configuration error somewhere, but I can't figure out where. Regular git commands appear to work fine, but "git diff" does nothing. To be safe, I removed external diff tools from my .gitconfig file. This was installed via MacPorts and is the lates version (1.7.2.2).

What I see is that when I run "git diff" from my workspace, it simply exits, doing nothing.

$ git --version
git version 1.7.2.2
$ git diff
$ 

If I back up one directory, out of my root workspace, typing "git diff" gives me this:

$ git diff
usage: git diff [--no-index] <path> <path>

This may be expected behavior since I'm not under a git repository.

Any ideas on what I can do to troubleshoot this?

A: 

It does nothing if your working directory is clean and there are no differences from the last update. Try editing a file and then run git diff again, and it should then show the diff.

Jaanus
+2  A: 

It means that there are no changed files.

emostar
Sorry I wasn't clear on this point - there are *many* changed files in my workspace.
tlianza
did you already do a 'git add'? If that is the case, they are staged, so you will need to run 'git diff --cached'
emostar
+1  A: 

The default output for git diff is the list of changes which have not been committed / added to the index. If there are no changes, then there is no output.

git diff [--options] [--] […]

This form is to view the changes you made relative to the index (staging area for the next commit). In other words, the differences are what you could tell git to further add to the index but you still haven't.

See the documentation for more details. In particular, scroll down to the examples, and read this section:

$ git diff            (1)
$ git diff --cached   (2)
$ git diff HEAD       (3)
  1. Diff the working copy with the index
  2. Diff the index with HEAD
  3. Diff the working copy with HEAD

Outside your workspace, as you guessed, git won't know what to diff, so you have to explicitly specify two paths to compare, hence the usage message.

Douglas
I'm not sure your answer is correct, but it did help me find the answer, so thank you and I'll mark it as such! The default output for git diff is *not* the list of uncommitted changes, it is the list of uncommitted changes that are _also_ "not yet staged for the next commit". So, the command that does what I was expecting "git diff" to do is actually "git diff HEAD".
tlianza
To complete the picture, use git diff --cached to show just what's in the index.
Douglas
+1  A: 

If you are using it outside of a real repository or work-copy, its behaviour is identical to the GNU diff. So you need to inform the 2 directories or files to be compared. Example:

git diff old_dir new_dir.

If there is any difference between them, the output will show you, as expected.

jweyrich