8

Every piece of documentation I've read on git (including the online book and the built-in help) says I can type "git diff" from command line, but whenever I do that I get:

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

Here's what I've tried so far (all are examples from the documentation):

$ git diff usage: git diff [--no-index] <path> <path> $ git diff HEAD usage: git diff [--no-index] <path> <path> $ git diff -- usage: git diff [--no-index] <path> <path> $ git diff -- . usage: git diff [--no-index] <path> <path> $ git diff --stat usage: git diff [--no-index] <path> <path> $ git --version git version 1.7.1 

Am I missing something here?

1
  • Oops... stackoverflow removed everything between angle brackets and removed the linefeed after each line that ends in a "tag". The "usage" text should be on the next line. The actual error message with parenthesis instead of angle brackets: "usage: git diff [--no-index] (path) (path)" Commented Jun 27, 2010 at 16:01

3 Answers 3

11

Are you actually inside a directory with a Git repository when you're running these? (git rev-parse --git-dir) The command needs to be able to find the repository and determine what your working tree is in order to produce useful output. Otherwise (if a repository cannot be identified), it defaults to being a plain recursive-diff command, and needs two paths to operate.

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah that was it. The documentation makes no mention of this "feature" of git diff. How did you guys know about this mode of operation?
@Karl: From the [ git diff manpage](kernel.org/pub/software/scm/git/docs/git-diff.html): “If exactly two paths are given, and at least one is untracked, compare the two files / directories. This behavior can be forced by --no-index.”
1

Are you working in a git repository? If you do a git status, do you get something close to the following?

> $ git status > # On branch develop.new_feature > # Changed but not updated: > # (use "git add <file>..." to update what will be committed) > # > # modified: feature > # modified: www/jkll.jsp > # > # Untracked files: > # (use "git add <file>..." to include ... 

Comments

0

Use git diff --no-index. The [] means the argument is optional.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.