Short answer? You’re using it wrong or you mis-configured.
It works but not as you think it does
Most common. You expected something different. Perhaps you worked on Mercurial recently? Or perhaps you thought default behaviour should be something else in your case?
This should help:
- By default it compares index and working dir, nothing in index means nothing to show)
- If you wish to see what will be in next commit, use `
--staged` or `
- for comparing files use either paths or `
- for branches, make sure they don’t point to same commit
Either (most likely) a pager or mishandled permissions on a file. To correct:
# sets less as default pager
git config --global core.pager 'less'
# tells Git to ignore file modes
git config core.fileMode false
git diff` uses pager to show results. If you
- don’t have any pager or
- have removed the default one: `
less` (why would you?!) or
- have chosen another pager, or
- have configured it with auto-quit flags (
-F | --quit-if-one-screenor
-e | --quit-at-eof)
git diff` won’t show results even if they’re there. The last one deserves clarification. Usually you quit `
less` only via key q. However, if you run
less with extra options (or configure them for your user / system / whatever) then if you have only one screen of output, both flags will cause
less to auto-quit. Since
less doesn’t print to STDOUT, you lose the output.
For it’s config, check `
$LESS` env variable (contains options auto-passed to less with each call) or if you’re not calling it like `
less -options` somehow.
To eliminate pager, run `
git --no-pager diff [...]`. If this shows output, you know where the problem is.
If someone is using unusual permissions and you are on Windows (why?!) you may have to bite it. Outside of that I’m yet to see this. Follow-up with whoever has unusual permissions or set your Git to ignore them altogether.
Time for some git debug.
$ GIT_TRACE=2 git diff
trace: built-in: git 'diff'
trace: run_command: 'less'
trace: exec: 'less'
Wrong – not a git repository
Checked on version 1.9.1 and it can work outside of git repo. According to commits, since 1.8.5. Obviously, requires diff to be used with `
--no-index` or with two files (otherwise you WILL get error message).
Junio Hamano : git : 286bc123 – explains how it works.
Dale Worley : git : b214eddf – explains it further, when outside of the repo.
$ git diff
Not a git repository
To compare two paths outside a working tree:
usage: git diff [--no-index]