# 'git diff' against files outside a git repo

7 messages from 2010-09-24 to 2010-09-27. Participants: Avery Pennarun, Elijah Newren, Brandon Casey, Junio C Hamano, Michael J Gruber.
Thread: https://gitlist.dev/t/25233

## Avery Pennarun, 2010-09-24 22:23

Subject: 'git diff' against files outside a git repo
Message-ID: <AANLkTinR7BJpD-FOS_DShg=r0ucF2C9oE6p-YoZU-5En@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTinR7BJpD-FOS_DShg%3Dr0ucF2C9oE6p-YoZU-5En%40mail.gmail.com

```
Hi all,

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.

(For the curious: the particular "files" I want to compare are
actually split into a hierarchical tree of blobs using bup's rolling
checksum and *then* stored in git.  Obviously I have to reassemble
them before I can diff them, which is fine and easy, but I then want
to run 'git diff' against them, which seems to not be so easy.)

(For the extremely curious: the particular files I want to diff are
mega-gigantic csv files from database dumps.  Because of bup's tree
format, I should be able to zoom in on just the overall part of the
file that has changed, then diff only that, which will be much faster
than running a diff algorithm against the whole file.  Essentially
O(log n) vs. the file size.)

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?

Or should I stop trying to do this and use some other diff
implementation instead?

Another alternative would be to teach git directly how to act on
bup-style large objects, but that's... a lot of work.  And it's not
obvious that a patch to do so would be accepted anyhow, since
bup-style storage is necessarily not as space-efficient and is harder
to deltify.

Thanks,

Avery

```

## Elijah Newren, 2010-09-24 22:30

Subject: Re: 'git diff' against files outside a git repo
Message-ID: <AANLkTik4kL8Mao1VM=njNxFSXOY7guwuEZgmpv0UTc8R@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTik4kL8Mao1VM%3DnjNxFSXOY7guwuEZgmpv0UTc8R%40mail.gmail.com
In-Reply-To: <AANLkTinR7BJpD-FOS_DShg=r0ucF2C9oE6p-YoZU-5En@mail.gmail.com>

```
On Fri, Sep 24, 2010 at 4:23 PM, Avery Pennarun <apenwarr@gmail.com> wrote:
> Hi all,
>
> 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?

```

## Brandon Casey, 2010-09-24 22:30

Subject: Re: 'git diff' against files outside a git repo
Message-ID: <-30AUOVW2mMJiL1EZcTFG9LhiQWZDLcLpaLzWQHRY8tnzFEGXuZLuw@cipher.nrlssc.navy.mil>
URL: https://gitlist.dev/e/-30AUOVW2mMJiL1EZcTFG9LhiQWZDLcLpaLzWQHRY8tnzFEGXuZLuw%40cipher.nrlssc.navy.mil
In-Reply-To: <AANLkTinR7BJpD-FOS_DShg=r0ucF2C9oE6p-YoZU-5En@mail.gmail.com>

```
On 09/24/2010 05:23 PM, Avery Pennarun wrote:
> Hi all,
> 
> 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.
> 
> (For the curious: the particular "files" I want to compare are
> actually split into a hierarchical tree of blobs using bup's rolling
> checksum and *then* stored in git.  Obviously I have to reassemble
> them before I can diff them, which is fine and easy, but I then want
> to run 'git diff' against them, which seems to not be so easy.)
> 
> (For the extremely curious: the particular files I want to diff are
> mega-gigantic csv files from database dumps.  Because of bup's tree
> format, I should be able to zoom in on just the overall part of the
> file that has changed, then diff only that, which will be much faster
> than running a diff algorithm against the whole file.  Essentially
> O(log n) vs. the file size.)
> 
> Is there already a way to get 'git diff' to do this?

Doesn't

   git diff file.one file.two

work?

Or are you asking for something else?

-Brandon

```

## Avery Pennarun, 2010-09-25 07:45

Subject: Re: 'git diff' against files outside a git repo
Message-ID: <AANLkTikpPQM4GyP5O7+aw6_P9_1DdxUjTzpH=WhzW=wK@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTikpPQM4GyP5O7%2Baw6_P9_1DdxUjTzpH%3DWhzW%3DwK%40mail.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:
> 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

```

## Junio C Hamano, 2010-09-26 07:13

Subject: Re: 'git diff' against files outside a git repo
Message-ID: <7vwrq9m0y0.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vwrq9m0y0.fsf%40alter.siamese.dyndns.org
In-Reply-To: <AANLkTikpPQM4GyP5O7+aw6_P9_1DdxUjTzpH=WhzW=wK@mail.gmail.com>

```
Avery Pennarun <apenwarr@gmail.com> writes:

> 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.

Heh, I thought you've been using git long enough that you sh/would know
that you are comparing the index and the working tree, using "file1" and
"file2" as pathspecs.

```

## Avery Pennarun, 2010-09-26 09:38

Subject: Re: 'git diff' against files outside a git repo
Message-ID: <AANLkTikJ-SN5xmwqhEHcESfQCWvGjSHp3OK1Hi4+0jBL@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTikJ-SN5xmwqhEHcESfQCWvGjSHp3OK1Hi4%2B0jBL%40mail.gmail.com
In-Reply-To: <7vwrq9m0y0.fsf@alter.siamese.dyndns.org>

```
On Sun, Sep 26, 2010 at 12:13 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Avery Pennarun <apenwarr@gmail.com> writes:
>
>> 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.
>
> Heh, I thought you've been using git long enough that you sh/would know
> that you are comparing the index and the working tree, using "file1" and
> "file2" as pathspecs.

Ha, of course.  And I do that all the time, so it's silly that I
somehow forgot for the duration of that email.

The real surprise was that this *wasn't* the meaning when I was
outside a git tree :)

Have fun,

Avery

```

## Michael J Gruber, 2010-09-27 07:38

Subject: Re: 'git diff' against files outside a git repo
Message-ID: <4CA049FD.5040100@drmicha.warpmail.net>
URL: https://gitlist.dev/e/4CA049FD.5040100%40drmicha.warpmail.net
In-Reply-To: <AANLkTikJ-SN5xmwqhEHcESfQCWvGjSHp3OK1Hi4+0jBL@mail.gmail.com>

```
Avery Pennarun venit, vidit, dixit 26.09.2010 11:38:
> On Sun, Sep 26, 2010 at 12:13 AM, Junio C Hamano <gitster@pobox.com> wrote:
>> Avery Pennarun <apenwarr@gmail.com> writes:
>>
>>> 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.
>>
>> Heh, I thought you've been using git long enough that you sh/would know
>> that you are comparing the index and the working tree, using "file1" and
>> "file2" as pathspecs.
> 
> Ha, of course.  And I do that all the time, so it's silly that I
> somehow forgot for the duration of that email.
> 
> The real surprise was that this *wasn't* the meaning when I was
> outside a git tree :)

Well, DWIM really is DWYTIM ;)

Michael

```
