为什么我不在命令行上使用git diff?

时间:2010-06-27 16:00:02

标签: git diff

我在git上阅读的每一篇文档(包括在线书籍和内置帮助)都说我可以从命令行输入“git diff”,但每当我这样做时,我得到:

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

这是我到目前为止所尝试的内容(都是文档中的示例):

$ 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

我在这里错过了什么吗?

3 个答案:

答案 0 :(得分:9)

当你运行这些时,你实际上是在一个带有Git存储库的目录中吗? (git rev-parse --git-dir)该命令需要能够找到存储库并确定您的工作树是什么,以便产生有用的输出。否则(如果无法识别存储库),它默认为普通的recursive-diff命令,需要两个路径才能运行。

答案 1 :(得分:1)

您是否在git存储库中工作?如果您执行git状态,您是否接近以下内容?

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

答案 2 :(得分:0)

使用git diff --no-index[]表示参数是可选的。