git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* negated list in .gitignore no fun
@ 2008-12-18 21:53 jidanni
  2008-12-18 22:34 ` Boyd Stephen Smith Jr.
  2008-12-18 22:38 ` Linus Torvalds
  0 siblings, 2 replies; 4+ messages in thread
From: jidanni @ 2008-12-18 21:53 UTC (permalink / raw)
  To: git; +Cc: joey

I discovered git is so negative: it has very good .gitignore negative
matching facilities, but not as good positive matching facilities.
(Maybe positive glob lists are merely fed to git-add from the command line.)

I had dreams of tracking only a few files in a large tree.
I thought I would maintain that list as a negated list in .gitignore,
and then always use "git-add ." to keep git's index reflecting my list.

However that's just not possible.

# head -n 5 .gitignore
*
!X11/xorg.conf
!anacrontab
!apt/apt.conf.d/10jidanni
!apt/sources.list
# git-add .
But git-status only shows anacrontab got added. None of the files in
the subdirectories get added. We continue,
# sed -n s/^!//p .gitignore|xargs git-add #no help!
# sed -n s/^!//p .gitignore|xargs -n 1 git-add #Geez. Finally worked.
OK, I suppose my next step is just to rm .gitignore and just add any
future files I want to add to my list one by one with git-add... like
git was designed to do in the first place. OK, thanks. Bye.
Next episode: some kind of middle ground with etckeeper.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: negated list in .gitignore no fun
  2008-12-18 21:53 negated list in .gitignore no fun jidanni
@ 2008-12-18 22:34 ` Boyd Stephen Smith Jr.
  2008-12-18 22:38 ` Linus Torvalds
  1 sibling, 0 replies; 4+ messages in thread
From: Boyd Stephen Smith Jr. @ 2008-12-18 22:34 UTC (permalink / raw)
  To: jidanni; +Cc: git, joey

[-- Attachment #1: Type: text/plain, Size: 1071 bytes --]

On Thursday 2008 December 18 15:53:23 jidanni@jidanni.org wrote:
> # head -n 5 .gitignore
> *
> !X11/xorg.conf
> !anacrontab
> !apt/apt.conf.d/10jidanni
> !apt/sources.list
> # git-add .
> But git-status only shows anacrontab got added. None of the files in
> the subdirectories get added.

That's by design.  You've chosen to ignore those directories; they match "*" 
themselves.  Thus, 'git add .' doesn't descend into them looking for files.

I wouldn't want to change this behavior because I'll often use a "build" 
directory and put all generated files in it and just ignore that directory 
with a single line in .gitignore.

I think the .gitignore you really want is:
*
!X11
!X11/xorg.conf
!anacrontab
!apt
!apt/apt.conf.d
!apt/apt.conf.d/10jidanni
!apt/sources.list
[...]

But, I haven't tested that.
-- 
Boyd Stephen Smith Jr.                     ,= ,-_-. =. 
bss@iguanasuicide.net                     ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy           `-'(. .)`-' 
http://iguanasuicide.net/                      \_/     

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: negated list in .gitignore no fun
  2008-12-18 21:53 negated list in .gitignore no fun jidanni
  2008-12-18 22:34 ` Boyd Stephen Smith Jr.
@ 2008-12-18 22:38 ` Linus Torvalds
  2008-12-18 22:54   ` Linus Torvalds
  1 sibling, 1 reply; 4+ messages in thread
From: Linus Torvalds @ 2008-12-18 22:38 UTC (permalink / raw)
  To: jidanni; +Cc: git, joey



On Fri, 19 Dec 2008, jidanni@jidanni.org wrote:
> 
> I had dreams of tracking only a few files in a large tree.
> I thought I would maintain that list as a negated list in .gitignore,
> and then always use "git-add ." to keep git's index reflecting my list.
> 
> However that's just not possible.
> 
> # head -n 5 .gitignore
> *
> !X11/xorg.conf
> !anacrontab
> !apt/apt.conf.d/10jidanni
> !apt/sources.list
> # git-add .
> But git-status only shows anacrontab got added. None of the files in
> the subdirectories get added.

Yeah, the problem is that the '*' matches the subdirectories (like "X11"), 
but the negative matching does not. So the subdirectory gets ignored, and 
as a result, git won't even traverse into it and notice that there's a 
file in there that shouldn't be ignored.

It's actually logical, but not what you want.

So you have several possibilities:

 (a) either create a .gitignore that looks like this:

	*
	!X11
	!X11/xorg.conf
	!anacrontab
	!apt
	!apt/apt.conf.d
	!apt/apt.conf.d/10jidanni
	!apt/sources.list

    which should work around it by telling git that it shouldn't ignore 
    the subdirectories.

 (b) realize that ".gitignore" only matters for files that git doesn't 
     already know about, so if you only want to track a small set of 
     files, what you _should_ do is just do a .gitignore that looks like 
     this:

	*

     and then just force-add the few files you want to track, using 
     something like

	git add -f X11/xorg.conf anacrontab apt/apt.conf.d/10jidanni apt/sources.list

     and now you're done - git won't ignore them, since explciitly you 
     told git to track them.

 (c) Try to teach git to not ignore subdirectories leading up to 
     non-ignored files, and give you the .gitignore semantics you like. I 
     suspect it's not worth it, because the git behaviour is logical once 
     you know about it and understand it.

.. and possibly other things you could do too.

			Linus

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: negated list in .gitignore no fun
  2008-12-18 22:38 ` Linus Torvalds
@ 2008-12-18 22:54   ` Linus Torvalds
  0 siblings, 0 replies; 4+ messages in thread
From: Linus Torvalds @ 2008-12-18 22:54 UTC (permalink / raw)
  To: jidanni; +Cc: git, joey



On Thu, 18 Dec 2008, Linus Torvalds wrote:
> 
> So you have several possibilities:
> 
>  (a) either create a .gitignore that looks like this:
> 
> 	*
> 	!X11
> 	!X11/xorg.conf
> 	!anacrontab
> 	!apt
> 	!apt/apt.conf.d
> 	!apt/apt.conf.d/10jidanni
> 	!apt/sources.list
> 
>     which should work around it by telling git that it shouldn't ignore 
>     the subdirectories.

Oh, you should have a '/' there in the subdirectory marker too, because 
otherwise a file like 'X11/apt' would now match as a positive match.

>  (c) Try to teach git to not ignore subdirectories leading up to 
>      non-ignored files, and give you the .gitignore semantics you like. I 
>      suspect it's not worth it, because the git behaviour is logical once 
>      you know about it and understand it.

.. and because of subtle issues like this - negated entries are really 
quite complex enough as-is. Don't use them for anything subtle, you _will_ 
get them wrong regardless.

			Linus

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-12-18 23:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-18 21:53 negated list in .gitignore no fun jidanni
2008-12-18 22:34 ` Boyd Stephen Smith Jr.
2008-12-18 22:38 ` Linus Torvalds
2008-12-18 22:54   ` Linus Torvalds

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).