I hate seeing nearly every directory in my repository list each file twice, once with a dot in front of it and once without. I tried adding .* to my .hgignore file, but it has no effect. Is this the wrong syntax, and more importantly, is it a bad idea to try this in the first place? Thanks.
2 Answers
You've got almost the right answer in the comments from gavinb, but the match was a little to broad. However, key concept about ignoring after the face was provided by RogerPage, again in a comment (what's with everyone preferring comments to answers?).
Let's look at these nine files:
dir.with.dots/file.with.dots
dir.with.dots/filewithoutdots
dir.with.dots/.filestartwithdot
dirwithoutdots/file.with.dots
dirwithoutdots/filewithoutdots
dirwithoutdots/.filestartwithdot
.startwithdot/file.with.dots
.startwithdot/filewithoutdots
.startwithdot/.filestartwithdot
If in the default regex mode for hgignore you do:
\..*
You ignore eight of those nine files:
$ hg stat -i
I .hgignore
I .startwithdot/.filestartwithdot
I .startwithdot/file.with.dots
I .startwithdot/filewithoutdots
I dir.with.dots/.filestartwithdot
I dir.with.dots/file.with.dots
I dir.with.dots/filewithoutdots
I dirwithoutdots/.filestartwithdot
I dirwithoutdots/file.with.dots
which is more broad than you said you wanted. It's ignoring anything with a dot anywhere in it.
To ignore all files and directores (not what you said, but what you seem to want) beginning with a dot you use this regexp pattern:
(^|/)\.
which says that the thing before the literal dot has to be the start of the line (^) or a slash.
$ hg stat -i
I .hgignore
I .startwithdot/.filestartwithdot
I .startwithdot/file.with.dots
I .startwithdot/filewithoutdots
I dir.with.dots/.filestartwithdot
I dirwithoutdots/.filestartwithdot
That caught only files or directories that start with a dot.
However, the other key concept that came up, was that .hgignore has no effect after a file has been added. It will prevent adding by wild card, but you can always override .hgignore with an explicit hg add. and once files have been added the hgignore is no longer consulted.
That's actually really handy because you can ignore broadly (ex: .*\.jar) and then add the exceptions you do want manually w/o having to futz with your hgignore file. However, in this case it means you need to hg rm the files you've already added accidentally, and tonfa showed how to do that (so long as there are no spaces in your filenames).
In the end it sounds like what you want in your .hgignore file is:
(^|/)\._
and that you need to remove the ones you've already added:
find . -type f -name "._*" -print0 |xargs -0 hg rm
\..*but it is very suspicious that you describe having all files, with a dot and without. You wouldn't ordinarily have dot files in a repo. What files are you tracking? (hg manifest) - gavinbhg addremove, and did a commit, and they are all still in my repository. - user123003syntax: reabove the directive). But.*is correct glob syntax. If the files are already committed, you'll have to remove them individually (or withhg rm .*), and addremove won't do this for you. - Roger Patesudo hg rm .*doesn't work. I getabort: .. not under rootwhich doesn't make sense to me. All of the hidden files in question are actually._files that the OSX Finder creates for some reason. I tried running their built-indot_cleanutility, but I getundouble . failed. Very frustrating. - user123003find . -name "._*" |xargs hg rm- tonfa