Re: refining .gitignores

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: refining .gitignores

From: Bruce Stephens <hidden>
Date: 2016-06-15 22:43:51

Alex Riesen [off-list ref] writes:
Bruce Stephens, Wed, Nov 14, 2007 23:36:06 +0100:
quoted
How do I get a list of files (in HEAD, say) that would be ignored by
the .gitignore files (and the other usual settings)?

It feels like something like this ought to work:

     git ls-files -z | xargs -0 git ls-files --ignored

But listing its arguments that are ignored by .gitignore (etc.)
doesn't seem to be what "git ls-files --ignored" does.  Or at least,
not quite as straightforwardly as that.
git ls-files --exclude-per-directory=.gitignore -X .git/info/exclude -i -o
That doesn't seem to work.

For example, if I add '*.c' to .gitignores in git.git, I can't seem to
get that command to display any .c files.

Run on its own, it displays lots of files, but no .c files.  Run with
an argument (such as builtin-add.c), it displays nothing.
quoted
The motivation is (obviously) that I fear some of the .gitignore
patterns are too broad, and a reasonable check is that none of the
files that are already committed would be caught by the patterns.
git ls-files --exclude-per-directory=.gitignore -X .git/info/exclude -i
That also doesn't seem to do quite what I want, and probably in the
same way.  I see git add returns non-zero error status if a file is
ignored, so I can do it with

excluded=()
for f in $(git ls-files)
do
    git add $f || excluded=($excluded $f)
done

But that feels kind of clunky.  I feel I'm missing something basic
about how git ls-files is intended to work, or something.

Re: refining .gitignores

From: Alex Riesen <hidden>
Date: 2016-06-15 22:43:51

Bruce Stephens, Thu, Nov 15, 2007 12:39:45 +0100:
Alex Riesen [off-list ref] writes:
quoted
Bruce Stephens, Wed, Nov 14, 2007 23:36:06 +0100:
quoted
How do I get a list of files (in HEAD, say) that would be ignored by
the .gitignore files (and the other usual settings)?

It feels like something like this ought to work:

     git ls-files -z | xargs -0 git ls-files --ignored

But listing its arguments that are ignored by .gitignore (etc.)
doesn't seem to be what "git ls-files --ignored" does.  Or at least,
not quite as straightforwardly as that.
git ls-files --exclude-per-directory=.gitignore -X .git/info/exclude -i -o
That doesn't seem to work.

For example, if I add '*.c' to .gitignores in git.git, I can't seem to
get that command to display any .c files.
.gitignore? Without "s"?
Maybe your .c files are already added to index? Otherwise you have to
use the second form. It shows known-to-Git ignored files.
Run on its own, it displays lots of files, but no .c files.  Run with
an argument (such as builtin-add.c), it displays nothing.
because the *are* in the index. "-o" means "others", as in "not Git".
quoted
quoted
The motivation is (obviously) that I fear some of the .gitignore
patterns are too broad, and a reasonable check is that none of the
files that are already committed would be caught by the patterns.
git ls-files --exclude-per-directory=.gitignore -X .git/info/exclude -i
That also doesn't seem to do quite what I want, and probably in the
same way. ...
It shows ignored files from the "known-to-Git" fileset.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help