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?
There is no output to git diff because Git doesn't see any changes inside your repository, only files outside the repository, which it considers 'untracked' and so ignores when generating a diff.
Comparing changes with git diff Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more.
The diff can be done with git diff (followed by the filename or nothing if you want to see the diff of all modified files). But if you already did something like git add * , you have to undo with git restore --staged .
You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch. Order does matter when you're comparing branches.
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)
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:
git diff --no-index
can act like a regular (non-git) diff
.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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With