{"thread":{"id":"16788","subject":"negated list in .gitignore no fun","startedAt":"2008-12-18T21:53:23Z","lastAt":"2008-12-18T22:54:18Z","messageCount":4,"participants":["jidanni@jidanni.org","Linus Torvalds","Boyd Stephen Smith Jr."],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"98293","messageId":"87hc51tajw.fsf@jidanni.org","threadId":"16788","inReplyTo":null,"subject":"negated list in .gitignore no fun","fromName":"","fromEmail":"jidanni@jidanni.org","sentAt":"2008-12-18T21:53:23Z","receivedAt":"2008-12-18T21:53:23Z","isPatch":false,"sender":{"key":"jidanni@jidanni.org","avatar":"https://gravatar.com/avatar/36568d4af4c8d3e71627ef3b8c8d00e39065b12f29676cccd38ced75e68fa2a6?d=mp&s=160"},"body":"I discovered git is so negative: it has very good .gitignore negative\nmatching facilities, but not as good positive matching facilities.\n(Maybe positive glob lists are merely fed to git-add from the command line.)\n\nI had dreams of tracking only a few files in a large tree.\nI thought I would maintain that list as a negated list in .gitignore,\nand then always use \"git-add .\" to keep git's index reflecting my list.\n\nHowever that's just not possible.\n\n# head -n 5 .gitignore\n*\n!X11/xorg.conf\n!anacrontab\n!apt/apt.conf.d/10jidanni\n!apt/sources.list\n# git-add .\nBut git-status only shows anacrontab got added. None of the files in\nthe subdirectories get added. We continue,\n# sed -n s/^!//p .gitignore|xargs git-add #no help!\n# sed -n s/^!//p .gitignore|xargs -n 1 git-add #Geez. Finally worked.\nOK, I suppose my next step is just to rm .gitignore and just add any\nfuture files I want to add to my list one by one with git-add... like\ngit was designed to do in the first place. OK, thanks. Bye.\nNext episode: some kind of middle ground with etckeeper.\n"},{"id":"98297","messageId":"200812181634.51351.bss@iguanasuicide.net","threadId":"16788","inReplyTo":"87hc51tajw.fsf@jidanni.org","subject":"Re: negated list in .gitignore no fun","fromName":"Boyd Stephen Smith Jr.","fromEmail":"bss@iguanasuicide.net","sentAt":"2008-12-18T22:34:47Z","receivedAt":"2008-12-18T22:34:47Z","isPatch":false,"sender":{"key":"bss@iguanasuicide.net","avatar":"https://gravatar.com/avatar/84b95eeff194b816c1568b1339e63e4b229825298664a9037b9f1ec713ead1e3?d=mp&s=160"},"body":"On Thursday 2008 December 18 15:53:23 jidanni@jidanni.org wrote:\n> # head -n 5 .gitignore\n> *\n> !X11/xorg.conf\n> !anacrontab\n> !apt/apt.conf.d/10jidanni\n> !apt/sources.list\n> # git-add .\n> But git-status only shows anacrontab got added. None of the files in\n> the subdirectories get added.\n\nThat's by design.  You've chosen to ignore those directories; they match \"*\" \nthemselves.  Thus, 'git add .' doesn't descend into them looking for files.\n\nI wouldn't want to change this behavior because I'll often use a \"build\" \ndirectory and put all generated files in it and just ignore that directory \nwith a single line in .gitignore.\n\nI think the .gitignore you really want is:\n*\n!X11\n!X11/xorg.conf\n!anacrontab\n!apt\n!apt/apt.conf.d\n!apt/apt.conf.d/10jidanni\n!apt/sources.list\n[...]\n\nBut, I haven't tested that.\n-- \nBoyd Stephen Smith Jr.                     ,= ,-_-. =. \nbss@iguanasuicide.net                     ((_/)o o(\\_))\nICQ: 514984 YM/AIM: DaTwinkDaddy           `-'(. .)`-' \nhttp://iguanasuicide.net/                      \\_/     \n"},{"id":"98295","messageId":"alpine.LFD.2.00.0812181429100.14014@localhost.localdomain","threadId":"16788","inReplyTo":"87hc51tajw.fsf@jidanni.org","subject":"Re: negated list in .gitignore no fun","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2008-12-18T22:38:30Z","receivedAt":"2008-12-18T22:38:30Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Fri, 19 Dec 2008, jidanni@jidanni.org wrote:\n> \n> I had dreams of tracking only a few files in a large tree.\n> I thought I would maintain that list as a negated list in .gitignore,\n> and then always use \"git-add .\" to keep git's index reflecting my list.\n> \n> However that's just not possible.\n> \n> # head -n 5 .gitignore\n> *\n> !X11/xorg.conf\n> !anacrontab\n> !apt/apt.conf.d/10jidanni\n> !apt/sources.list\n> # git-add .\n> But git-status only shows anacrontab got added. None of the files in\n> the subdirectories get added.\n\nYeah, the problem is that the '*' matches the subdirectories (like \"X11\"), \nbut the negative matching does not. So the subdirectory gets ignored, and \nas a result, git won't even traverse into it and notice that there's a \nfile in there that shouldn't be ignored.\n\nIt's actually logical, but not what you want.\n\nSo you have several possibilities:\n\n (a) either create a .gitignore that looks like this:\n\n\t*\n\t!X11\n\t!X11/xorg.conf\n\t!anacrontab\n\t!apt\n\t!apt/apt.conf.d\n\t!apt/apt.conf.d/10jidanni\n\t!apt/sources.list\n\n    which should work around it by telling git that it shouldn't ignore \n    the subdirectories.\n\n (b) realize that \".gitignore\" only matters for files that git doesn't \n     already know about, so if you only want to track a small set of \n     files, what you _should_ do is just do a .gitignore that looks like \n     this:\n\n\t*\n\n     and then just force-add the few files you want to track, using \n     something like\n\n\tgit add -f X11/xorg.conf anacrontab apt/apt.conf.d/10jidanni apt/sources.list\n\n     and now you're done - git won't ignore them, since explciitly you \n     told git to track them.\n\n (c) Try to teach git to not ignore subdirectories leading up to \n     non-ignored files, and give you the .gitignore semantics you like. I \n     suspect it's not worth it, because the git behaviour is logical once \n     you know about it and understand it.\n\n.. and possibly other things you could do too.\n\n\t\t\tLinus\n"},{"id":"98296","messageId":"alpine.LFD.2.00.0812181452030.14014@localhost.localdomain","threadId":"16788","inReplyTo":"alpine.LFD.2.00.0812181429100.14014@localhost.localdomain","subject":"Re: negated list in .gitignore no fun","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2008-12-18T22:54:18Z","receivedAt":"2008-12-18T22:54:18Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Thu, 18 Dec 2008, Linus Torvalds wrote:\n> \n> So you have several possibilities:\n> \n>  (a) either create a .gitignore that looks like this:\n> \n> \t*\n> \t!X11\n> \t!X11/xorg.conf\n> \t!anacrontab\n> \t!apt\n> \t!apt/apt.conf.d\n> \t!apt/apt.conf.d/10jidanni\n> \t!apt/sources.list\n> \n>     which should work around it by telling git that it shouldn't ignore \n>     the subdirectories.\n\nOh, you should have a '/' there in the subdirectory marker too, because \notherwise a file like 'X11/apt' would now match as a positive match.\n\n>  (c) Try to teach git to not ignore subdirectories leading up to \n>      non-ignored files, and give you the .gitignore semantics you like. I \n>      suspect it's not worth it, because the git behaviour is logical once \n>      you know about it and understand it.\n\n.. and because of subtle issues like this - negated entries are really \nquite complex enough as-is. Don't use them for anything subtle, you _will_ \nget them wrong regardless.\n\n\t\t\tLinus\n"}]}