{"thread":{"id":"10871","subject":"refining .gitignores","startedAt":"2007-11-14T22:36:06Z","lastAt":"2007-11-15T21:56:26Z","messageCount":9,"participants":["Bruce Stephens","Alex Riesen","Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"59884","messageId":"804pfobgkp.fsf@tiny.isode.net","threadId":"10871","inReplyTo":null,"subject":"refining .gitignores","fromName":"Bruce Stephens","fromEmail":"bruce.stephens@isode.com","sentAt":"2007-11-14T22:36:06Z","receivedAt":"2007-11-14T22:36:06Z","isPatch":false,"sender":{"key":"bruce.stephens@isode.com","avatar":null},"body":"How do I get a list of files (in HEAD, say) that would be ignored by\nthe .gitignore files (and the other usual settings)?\n\nIt feels like something like this ought to work:\n\n     git ls-files -z | xargs -0 git ls-files --ignored\n\nBut listing its arguments that are ignored by .gitignore (etc.)\ndoesn't seem to be what \"git ls-files --ignored\" does.  Or at least,\nnot quite as straightforwardly as that.\n\nThe motivation is (obviously) that I fear some of the .gitignore\npatterns are too broad, and a reasonable check is that none of the\nfiles that are already committed would be caught by the patterns.\n"},{"id":"59886","messageId":"20071114230258.GG3973@steel.home","threadId":"10871","inReplyTo":"804pfobgkp.fsf@tiny.isode.net","subject":"Re: refining .gitignores","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-11-14T23:02:58Z","receivedAt":"2007-11-14T23:02:58Z","isPatch":false,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Bruce Stephens, Wed, Nov 14, 2007 23:36:06 +0100:\n> How do I get a list of files (in HEAD, say) that would be ignored by\n> the .gitignore files (and the other usual settings)?\n> \n> It feels like something like this ought to work:\n> \n>      git ls-files -z | xargs -0 git ls-files --ignored\n> \n> But listing its arguments that are ignored by .gitignore (etc.)\n> doesn't seem to be what \"git ls-files --ignored\" does.  Or at least,\n> not quite as straightforwardly as that.\n\ngit ls-files --exclude-per-directory=.gitignore -X .git/info/exclude -i -o\n\n> The motivation is (obviously) that I fear some of the .gitignore\n> patterns are too broad, and a reasonable check is that none of the\n> files that are already committed would be caught by the patterns.\n\ngit ls-files --exclude-per-directory=.gitignore -X .git/info/exclude -i\n\n(IOW, remove the -o aka --others)\n"},{"id":"59972","messageId":"807ikj3fge.fsf@tiny.isode.net","threadId":"10871","inReplyTo":"20071114230258.GG3973@steel.home","subject":"Re: refining .gitignores","fromName":"Bruce Stephens","fromEmail":"bruce.stephens@isode.com","sentAt":"2007-11-15T11:39:45Z","receivedAt":"2007-11-15T11:39:45Z","isPatch":false,"sender":{"key":"bruce.stephens@isode.com","avatar":null},"body":"Alex Riesen <raa.lkml@gmail.com> writes:\n\n> Bruce Stephens, Wed, Nov 14, 2007 23:36:06 +0100:\n>> How do I get a list of files (in HEAD, say) that would be ignored by\n>> the .gitignore files (and the other usual settings)?\n>> \n>> It feels like something like this ought to work:\n>> \n>>      git ls-files -z | xargs -0 git ls-files --ignored\n>> \n>> But listing its arguments that are ignored by .gitignore (etc.)\n>> doesn't seem to be what \"git ls-files --ignored\" does.  Or at least,\n>> not quite as straightforwardly as that.\n>\n> git ls-files --exclude-per-directory=.gitignore -X .git/info/exclude -i -o\n\nThat doesn't seem to work.\n\nFor example, if I add '*.c' to .gitignores in git.git, I can't seem to\nget that command to display any .c files.\n\nRun on its own, it displays lots of files, but no .c files.  Run with\nan argument (such as builtin-add.c), it displays nothing.\n\n>> The motivation is (obviously) that I fear some of the .gitignore\n>> patterns are too broad, and a reasonable check is that none of the\n>> files that are already committed would be caught by the patterns.\n>\n> git ls-files --exclude-per-directory=.gitignore -X .git/info/exclude -i\n\nThat also doesn't seem to do quite what I want, and probably in the\nsame way.  I see git add returns non-zero error status if a file is\nignored, so I can do it with\n\nexcluded=()\nfor f in $(git ls-files)\ndo\n    git add $f || excluded=($excluded $f)\ndone\n\nBut that feels kind of clunky.  I feel I'm missing something basic\nabout how git ls-files is intended to work, or something.\n"},{"id":"60015","messageId":"20071115192654.GA3552@steel.home","threadId":"10871","inReplyTo":"807ikj3fge.fsf@tiny.isode.net","subject":"Re: refining .gitignores","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-11-15T19:26:54Z","receivedAt":"2007-11-15T19:26:54Z","isPatch":false,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Bruce Stephens, Thu, Nov 15, 2007 12:39:45 +0100:\n> Alex Riesen <raa.lkml@gmail.com> writes:\n> > Bruce Stephens, Wed, Nov 14, 2007 23:36:06 +0100:\n> >> How do I get a list of files (in HEAD, say) that would be ignored by\n> >> the .gitignore files (and the other usual settings)?\n> >> \n> >> It feels like something like this ought to work:\n> >> \n> >>      git ls-files -z | xargs -0 git ls-files --ignored\n> >> \n> >> But listing its arguments that are ignored by .gitignore (etc.)\n> >> doesn't seem to be what \"git ls-files --ignored\" does.  Or at least,\n> >> not quite as straightforwardly as that.\n> >\n> > git ls-files --exclude-per-directory=.gitignore -X .git/info/exclude -i -o\n> \n> That doesn't seem to work.\n> \n> For example, if I add '*.c' to .gitignores in git.git, I can't seem to\n> get that command to display any .c files.\n\n.gitignore? Without \"s\"?\nMaybe your .c files are already added to index? Otherwise you have to\nuse the second form. It shows known-to-Git ignored files.\n\n> Run on its own, it displays lots of files, but no .c files.  Run with\n> an argument (such as builtin-add.c), it displays nothing.\n\nbecause the *are* in the index. \"-o\" means \"others\", as in \"not Git\".\n\n> >> The motivation is (obviously) that I fear some of the .gitignore\n> >> patterns are too broad, and a reasonable check is that none of the\n> >> files that are already committed would be caught by the patterns.\n> >\n> > git ls-files --exclude-per-directory=.gitignore -X .git/info/exclude -i\n> \n> That also doesn't seem to do quite what I want, and probably in the\n> same way. ...\n\nIt shows ignored files from the \"known-to-Git\" fileset.\n"},{"id":"60019","messageId":"80ejerdzjd.fsf@tiny.isode.net","threadId":"10871","inReplyTo":"20071115192654.GA3552@steel.home","subject":"Re: refining .gitignores","fromName":"Bruce Stephens","fromEmail":"bruce.stephens@isode.com","sentAt":"2007-11-15T20:28:06Z","receivedAt":"2007-11-15T20:28:06Z","isPatch":false,"sender":{"key":"bruce.stephens@isode.com","avatar":null},"body":"Alex Riesen <raa.lkml@gmail.com> writes:\n\n[...]\n\n> .gitignore? Without \"s\"?\n\nYes, my mistake.  I added '*.c' to \".gitignore\".\n\n> Maybe your .c files are already added to index? Otherwise you have to\n> use the second form. It shows known-to-Git ignored files.\n\nThey are in the index.  What I want is a list of files which are known\nto git, which are matched by the default rules (in particular the\n.gitignore files).\n\nSo that should be this?\n\n    git ls-files --exclude-per-directory=.gitignore -i\n\nBut that shows nothing at all, and it still shows nothing if I add a\n\"builtin-add.c\" as an argument to it (this file exists, and is in the\nindex).\n\n\"git add builtin-add.c\" fails, complaining (correctly) that the path\nis ignored by one of my .gitignore files.\n\nWe're obviously talking past one another somehow, or I have a broken\nbuild of git?\n\n[...]\n"},{"id":"60020","messageId":"alpine.LFD.0.9999.0711151237550.4260@woody.linux-foundation.org","threadId":"10871","inReplyTo":"80ejerdzjd.fsf@tiny.isode.net","subject":"Re: refining .gitignores","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2007-11-15T20:40:14Z","receivedAt":"2007-11-15T20:40:14Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Thu, 15 Nov 2007, Bruce Stephens wrote:\n>\n> They are in the index.  What I want is a list of files which are known\n> to git, which are matched by the default rules (in particular the\n> .gitignore files).\n\nAhh.\n\n*All* the .gitignore rules are purely about files that git does not \nalready know about. Once git tracks a pathname, the ignore rules simply \ndo not matter.\n\nFiles that are in the index are simply never ignored. There's no way to \nignore them, and in fact, the whole \"git add -f\" thing is a way to add \nfiles to the index and override the exclude rules - at which point git \nthen tracks them regardless of any such exclude rules.\n\n\t\t\tLinus\n"},{"id":"60022","messageId":"807ikjdxgf.fsf@tiny.isode.net","threadId":"10871","inReplyTo":"alpine.LFD.0.9999.0711151237550.4260@woody.linux-foundation.org","subject":"Re: refining .gitignores","fromName":"Bruce Stephens","fromEmail":"bruce.stephens@isode.com","sentAt":"2007-11-15T21:13:04Z","receivedAt":"2007-11-15T21:13:04Z","isPatch":false,"sender":{"key":"bruce.stephens@isode.com","avatar":null},"body":"Linus Torvalds <torvalds@linux-foundation.org> writes:\n\n> On Thu, 15 Nov 2007, Bruce Stephens wrote:\n>>\n>> They are in the index.  What I want is a list of files which are known\n>> to git, which are matched by the default rules (in particular the\n>> .gitignore files).\n>\n> Ahh.\n>\n> *All* the .gitignore rules are purely about files that git does not \n> already know about. Once git tracks a pathname, the ignore rules simply \n> do not matter.\n>\n> Files that are in the index are simply never ignored. There's no way to \n> ignore them, and in fact, the whole \"git add -f\" thing is a way to add \n> files to the index and override the exclude rules - at which point git \n> then tracks them regardless of any such exclude rules.\n\nOK.  I think I sort of understood that, but it's nice to have it\nclearly stated.\n\nI'm not worried so much about files that already exist.  I'm worried\nthat we may in the future create files that we want to store in git\nand which are ignored.  If we do that there's a chance we'll miss them\n(because \"git gui\", \"git status\", etc., won't bring attention to\nthem).\n\nSo it seemed valuable to try to make the .gitignore patterns precise:\nso that they ignore all the generated files that our builds produce,\nwhile not matching any files that git knows about.\n\nThat certainly wouldn't guarantee that new files wouldn't be caught by\nthe patterns, but it ought to lower the probability of this, since\nthere's a decent chance that such files will either be not touched by\nthe patterns (because they're *.java or something), or they'll fit\ninto one of the already handled exceptions (Doxyfile.local is one:\nmost *.local files are build products, but Doxyfile.local aren't).\n\nI guess if you're starting off with some project in git then this\nisn't such an issue: you evolve the patterns and the build process and\nso on in parallel.  So maybe there's not such a demand for finding\nthis information, and those of us who do want to do it are best using\nthe \"git add\" loop approach?\n"},{"id":"60024","messageId":"20071115211727.GC3552@steel.home","threadId":"10871","inReplyTo":"80ejerdzjd.fsf@tiny.isode.net","subject":"Re: refining .gitignores","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-11-15T21:17:27Z","receivedAt":"2007-11-15T21:17:27Z","isPatch":false,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Bruce Stephens, Thu, Nov 15, 2007 21:28:06 +0100:\n> Alex Riesen <raa.lkml@gmail.com> writes:\n> \n> [...]\n> \n> > .gitignore? Without \"s\"?\n> \n> Yes, my mistake.  I added '*.c' to \".gitignore\".\n> \n> > Maybe your .c files are already added to index? Otherwise you have to\n> > use the second form. It shows known-to-Git ignored files.\n> \n> They are in the index.  What I want is a list of files which are known\n> to git, which are matched by the default rules (in particular the\n> .gitignore files).\n> \n> So that should be this?\n> \n>     git ls-files --exclude-per-directory=.gitignore -i\n\nYes, so it seems. The per-directory ignore-files don't work.\n\"--exclude-from=\" (aka -X) still does.\n\n> But that shows nothing at all, and it still shows nothing if I add a\n> \"builtin-add.c\" as an argument to it (this file exists, and is in the\n> index).\n> \n> \"git add builtin-add.c\" fails, complaining (correctly) that the path\n> is ignored by one of my .gitignore files.\n> \n> We're obviously talking past one another somehow, or I have a broken\n> build of git?\n\nNo, I honestly believed that Git-known files can be ignored. According\nto Linus I must be wrong, but I have an excuse:\n\n    $ mkdir aaa\n    $ cd aaa\n    $ git init\n    Initialized empty Git repository in .git/\n    $ uname >abc\n    $ git add .\n    $ ls > .gitignore\n    $ git ls-files -X .gitignore\n    $ git ls-files -X .gitignore -i\n    abc\n"},{"id":"60029","messageId":"alpine.LFD.0.9999.0711151349560.4260@woody.linux-foundation.org","threadId":"10871","inReplyTo":"20071115211727.GC3552@steel.home","subject":"Re: refining .gitignores","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2007-11-15T21:56:26Z","receivedAt":"2007-11-15T21:56:26Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Thu, 15 Nov 2007, Alex Riesen wrote:\n> \n> No, I honestly believed that Git-known files can be ignored. According\n> to Linus I must be wrong, but I have an excuse:\n\nI do think we're not necessarily entirely consistent wrt ignore files.\n\nIn particular, git-ls-files itself actually is pretty special, because it \nhas two totally different modes:\n\n - you can ask for \"other\" files (and this is where you'd be expected to \n   use .gitignore)\n\n - you can just list the files git knows about (and this is where you'd \n   generally be expected to *not* use .gitignore)\n\n..and to make matters more interesting, \"git add\" used to do the former \n(it was just a thin script around \"git-ls-files -o\") but then was later \nenhanced to also take already-known files into account, so I am not at all \nsurprised if we actually get confused because we used to have a fairly \nclear separation of the two cases but then we started mixing them up.\n\nSo while I think that \".gitignore\" *should* only affect files that we \ndon't already know about (ie effectively only file lists that come from \n\"readdir()\", not from internal git data structures), I would not be at all \nsurprised if there are bugs.\n\n\t\tLinus\n"}]}