“git diff” does nothing

对着背影说爱祢 提交于 2019-12-02 16:27:34
Douglas

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.

Note: starting git 1.8.5 or 1.9, Q4 2013:

When the user types "git diff" outside a working tree, thinking he is inside one, the current error message that is a single-liner:

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

may not be sufficient to make him realize the mistake.

Add "Not a git repository" to the error message when we fell into the "--no-index" mode without an explicit command line option to instruct us to do so.


See:

Clarify documentation for "diff --no-index".
State that when not inside a repository, --no-index is implied and two arguments are mandatory.

Clarify error message from diff-no-index to inform user that CWD is not inside a repository and thus two arguments are mandatory.

To compare two paths outside a working tree:
usage: git diff --no-index <path> <path>

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.

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.

Not in your case, but maybe because the file that you pass not exists

$ git difftool HEAD HEAD^ -- path/that-not-exists

nothing happen

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!