git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [bug?] git diff --cached in a non-git directory

From
OTOkke Timm <okke@timm.sh>
Date
Sep 9, 2024, 15:51 UTC
Message-ID
<A95B257B-2414-43C7-B041-AC22B03D9143@timm.sh>
In-Reply-To
<05b501db02ce$3bd49e30$b37dda90$@nexbridge.com>
Show 55 quoted lines
> Am 09.09.2024 um 17:37 schrieb <rsbecker@nexbridge.com> <rsbecker@nexbridge.com>:
> 
> On September 9, 2024 10:26 AM, Okke Timm wrote:
>> What did you do before the bug happened? (Steps to reproduce your issue) I
>> changed into a non-git directory.
>> Then I called git with 'git diff --cached', which produced this error:
>> 
>> error: unknown option `cached'
>> usage: git diff --no-index [<options>] <path> <path> [...]
>> 
>> What did you expect to happen? (Expected behavior) A helfpul error message.
>> 
>> What happened instead? (Actual behavior) An unhelpful error message saying
> that
>> cached is an unknown option.
>> 
>> What's different between what you expected and what actually happened?
>> Me being confused why git suddenly forgot that `git diff --cached` is an
> allowed
>> option.
>> 
>> Anything else you want to add:
>> Please fix and thank you for this great tool!
>> 
>> Please review the rest of the bug report below.
>> You can delete any lines you don't wish to share.
>> 
>> 
>> [System Info]
>> git version:
>> git version 2.46.0
>> cpu: arm64
>> no commit associated with this build
>> sizeof-long: 8
>> sizeof-size_t: 8
>> shell-path: /bin/sh
>> feature: fsmonitor--daemon
>> libcurl: 8.4.0
>> zlib: 1.2.12
>> uname: Darwin 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:21 PDT
>> 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T8103 arm64 compiler info:
>> clang: 15.0.0 (clang-1500.3.9.4) libc info: no libc information available
> $SHELL
>> (typically, interactive shell): /opt/homebrew/bin/bash
>> 
>> 
>> [Enabled Hooks]
>> not run from a git repository - no hooks to show
> 
> Because you are not in a git repository clone, the --cached option has no
> meaning. It refers to the staging area only, so when not in a clone, git
> does not consider --cached as supported because there is no connection
> between an external directory and an internal. If you want to perform a diff
> from cached vs. external, run the git diff from inside the clone referencing
> the internal and external file after —.

i criticized the error message in my bug report. If it would tell me that this is not a git repository, I’d be happy. But telling me that `—cached` is not an allowed option for `git diff` is very unhelpful and confusing.

The reason why I reported this is that git gets run in tools these days and not all check for the presence of a git repository correctly all the time. Also sometimes permission issue hide the `.git` directory for some reason (reported for Windows and VSCode).

Previous: rsbecker@nexbridge.comNext: Junio C Hamano
Message 3 of 6 in “[bug?] git diff --cached in a non-git directory”
  1. Okke TimmSep 9, 2024
  2. rsbecker@nexbridge.comSep 9, 2024
  3. Okke TimmSep 9, 2024
  4. Junio C HamanoSep 9, 2024
  5. rsbecker@nexbridge.comSep 9, 2024
  6. Junio C HamanoSep 9, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.