# How to exclude files from "git diff"

7 messages from 2009-12-18 to 2010-01-05. Participants: H.J. Lu, Jeff King, Dmitry Potapov, Nguyen Thai Ngoc Duy, Junio C Hamano.
Thread: https://gitlist.dev/t/21984

## H.J. Lu, 2009-12-18 17:09

Subject: How to exclude files from "git diff"
Message-ID: <6dc9ffc80912180909q2e9cbe30r7c802a2152c5954@mail.gmail.com>
URL: https://gitlist.dev/e/6dc9ffc80912180909q2e9cbe30r7c802a2152c5954%40mail.gmail.com

```
Hi,

I have some bookkeeping files in my git repository.  How do I
exclude them from "git diff"? Does "git diff" support

# git diff --exclude="foo.*.bar*"

Please CC me since I am not on the git mailing list.

Thanks.


-- 
H.J.

```

## Jeff King, 2010-01-05 06:45

Subject: Re: How to exclude files from "git diff"
Message-ID: <20100105064509.GC19025@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20100105064509.GC19025%40coredump.intra.peff.net
In-Reply-To: <6dc9ffc80912180909q2e9cbe30r7c802a2152c5954@mail.gmail.com>

```
On Fri, Dec 18, 2009 at 09:09:15AM -0800, H.J. Lu wrote:

> I have some bookkeeping files in my git repository.  How do I
> exclude them from "git diff"? Does "git diff" support
> 
> # git diff --exclude="foo.*.bar*"

No, I don't believe there is a way to do that. You would have to do
something like:

  git diff $(git ls-files | grep -v whatever)

The usual concept of "exclusion" for git is not to track files at all
via the .gitignore mechanism.  Are these files that have content you
really _want_ in the repository, but you just don't want to see them
when doing some diffs? Or are they files that could not be in the
repository at all?

-Peff

```

## H.J. Lu, 2010-01-05 14:20

Subject: Re: How to exclude files from "git diff"
Message-ID: <6dc9ffc81001050620q55c23072p93f58c8685d77f9d@mail.gmail.com>
URL: https://gitlist.dev/e/6dc9ffc81001050620q55c23072p93f58c8685d77f9d%40mail.gmail.com
In-Reply-To: <20100105064509.GC19025@coredump.intra.peff.net>

```
On Mon, Jan 4, 2010 at 10:45 PM, Jeff King <peff@peff.net> wrote:
> On Fri, Dec 18, 2009 at 09:09:15AM -0800, H.J. Lu wrote:
>
>> I have some bookkeeping files in my git repository.  How do I
>> exclude them from "git diff"? Does "git diff" support
>>
>> # git diff --exclude="foo.*.bar*"
>
> No, I don't believe there is a way to do that. You would have to do
> something like:
>
>  git diff $(git ls-files | grep -v whatever)
>
> The usual concept of "exclusion" for git is not to track files at all
> via the .gitignore mechanism.  Are these files that have content you
> really _want_ in the repository, but you just don't want to see them
> when doing some diffs? Or are they files that could not be in the
> repository at all?

Yes, I want those files in repository. They are for my personal use only.

Thanks.

-- 
H.J.

```

## Dmitry Potapov, 2010-01-05 17:54

Subject: Re: How to exclude files from "git diff"
Message-ID: <37fcd2781001050954y778ba661n7cee6cda699968c2@mail.gmail.com>
URL: https://gitlist.dev/e/37fcd2781001050954y778ba661n7cee6cda699968c2%40mail.gmail.com
In-Reply-To: <6dc9ffc81001050620q55c23072p93f58c8685d77f9d@mail.gmail.com>

```
On Tue, Jan 5, 2010 at 5:20 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>
> Yes, I want those files in repository. They are for my personal use only.

If you modified some file locally and do not want to see and commit
those modifications, you may want to use:

git update-index --assume-unchanged foo

After that, git will not notice any change to `foo'. So, 'git diff' and any
other command (such git commit -a) will ignore those changes.

Warning: using  --assume-unchanged may result in losing your changes
if you switch between branches containing different versions of 'foo'.

Normally, when you try to do that, git will not allow switch to another
branch saying that `foo' is modified. But using --assume-unchanged
disables this check. But if you have the same `foo' on all branches
then switching between branches will preserve your modifications.


Dmitry

```

## H.J. Lu, 2010-01-05 18:15

Subject: Re: How to exclude files from "git diff"
Message-ID: <6dc9ffc81001051015x3bebc994r3d475bdb59e12d39@mail.gmail.com>
URL: https://gitlist.dev/e/6dc9ffc81001051015x3bebc994r3d475bdb59e12d39%40mail.gmail.com
In-Reply-To: <37fcd2781001050954y778ba661n7cee6cda699968c2@mail.gmail.com>

```
On Tue, Jan 5, 2010 at 9:54 AM, Dmitry Potapov <dpotapov@gmail.com> wrote:
> On Tue, Jan 5, 2010 at 5:20 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>
>> Yes, I want those files in repository. They are for my personal use only.
>
> If you modified some file locally and do not want to see and commit
> those modifications, you may want to use:
>
> git update-index --assume-unchanged foo
>

I added those files into my repository for bookkeeping purpose. It
shouldn't go out at all.


-- 
H.J.

```

## Nguyen Thai Ngoc Duy, 2010-01-05 18:31

Subject: Re: How to exclude files from "git diff"
Message-ID: <fcaeb9bf1001051031j6723dc14v8d43944e3b8baa90@mail.gmail.com>
URL: https://gitlist.dev/e/fcaeb9bf1001051031j6723dc14v8d43944e3b8baa90%40mail.gmail.com
In-Reply-To: <6dc9ffc81001051015x3bebc994r3d475bdb59e12d39@mail.gmail.com>

```
On 1/6/10, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Tue, Jan 5, 2010 at 9:54 AM, Dmitry Potapov <dpotapov@gmail.com> wrote:
>  > On Tue, Jan 5, 2010 at 5:20 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>  >>
>  >> Yes, I want those files in repository. They are for my personal use only.
>  >
>  > If you modified some file locally and do not want to see and commit
>  > those modifications, you may want to use:
>  >
>  > git update-index --assume-unchanged foo
>  >
>
>
> I added those files into my repository for bookkeeping purpose. It
>  shouldn't go out at all.

That could be a way to simulate git diff --exclude="foo*.bar*":

git ls-files -- 'foo*bar*'|xargs git update-index --assume-unchanged
git diff
git ls-files -- 'foo*bar*'|xargs git update-index --no-assume-unchanged

assume that you don't use assume-unchanged for any other purposes
-- 
Duy

```

## Junio C Hamano, 2010-01-05 18:41

Subject: Re: How to exclude files from "git diff"
Message-ID: <7vvdfgxum8.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vvdfgxum8.fsf%40alter.siamese.dyndns.org
In-Reply-To: <6dc9ffc81001051015x3bebc994r3d475bdb59e12d39@mail.gmail.com>

```
"H.J. Lu" <hjl.tools@gmail.com> writes:

> On Tue, Jan 5, 2010 at 9:54 AM, Dmitry Potapov <dpotapov@gmail.com> wrote:
>> On Tue, Jan 5, 2010 at 5:20 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>
>>> Yes, I want those files in repository. They are for my personal use only.
>>
>> If you modified some file locally and do not want to see and commit
>> those modifications, you may want to use:
>>
>> git update-index --assume-unchanged foo
>>
>
> I added those files into my repository for bookkeeping purpose. It
> shouldn't go out at all.

Sounds like time to run "rm --cached" to me.  IOW, keep it untracked.

```
