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.
threads / discuss / 21984
Subject: How to exclude files from "git diff"
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.
Re: How to exclude files from "git diff"
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
Re: How to exclude files from "git diff"
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.
Re: How to exclude files from "git diff"
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
Re: How to exclude files from "git diff"
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.
Re: How to exclude files from "git diff"
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
Re: How to exclude files from "git diff"
"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.