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

Re: 'git diff' against files outside a git repo

From
Avery Pennarun <apenwarr@gmail.com>
Date
Sep 25, 2010, 07:45 UTC
Message-ID
<AANLkTikpPQM4GyP5O7+aw6_P9_1DdxUjTzpH=WhzW=wK@mail.gmail.com>
In-Reply-To
<AANLkTik4kL8Mao1VM=njNxFSXOY7guwuEZgmpv0UTc8R@mail.gmail.com>
On Fri, Sep 24, 2010 at 3:30 PM, Elijah Newren <newren@gmail.com> wrote:
Show 15 quoted lines
> On Fri, Sep 24, 2010 at 4:23 PM, Avery Pennarun <apenwarr@gmail.com> wrote:
>> I'm interested in using 'git diff' on some files that aren't actually
>> inside a git repo at all.  Specifically, the --color-words and
>> --word-diff-regex are really cool and I happen to have a use for them
>> on files that aren't stored verbatim in git.  As a whole, git's
>> implementation of diff seems to be the fastest-moving one out there,
>> so I'd rather use it instead of another random diff implementation.
>>
> <snip>
>> Is there already a way to get 'git diff' to do this?
>>
>> If not, would it be sensible to extend git-diff to do comparison
>> between two outside files?
>
> Isn't this what git diff --no-index ... does?
Aha, that was exactly what I wanted. :)

Oddly, 'git diff file1 file2' *doesn't* work when file1 and file2 are in a working tree; git tries to diff something, apparently, but I don't know what. When you're outside a working tree, it works. And your "--no-index" suggestion is what makes it work even when you're in a working tree.

Thanks to you and Brandon for your help. I guess I'll try to submit a patch to the git-diff manpage to make this type of usage more obvious.

Have fun,
Avery
Previous: Elijah NewrenNext: Junio C Hamano
Message 3 of 7 in “'git diff' against files outside a git repo”
  1. Avery PennarunSep 24, 2010
  2. Elijah NewrenSep 24, 2010
  3. Avery PennarunSep 25, 2010
  4. Junio C HamanoSep 26, 2010
  5. Avery PennarunSep 26, 2010
  6. Michael J GruberSep 27, 2010
  7. Brandon CaseySep 24, 2010

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.