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.
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
I use this in my .hgignore
:
syntax: regexp
# dotfiles
(?<![^/])\.
Which reads: periods not preceded by something other than a forward slash.
Ry4an's solution is also good, I've used that one before too. Not sure which is more efficient.
© 2022 - 2024 — McMap. All rights reserved.
\..*
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
) – Equilateralhg addremove
, and did a commit, and they are all still in my repository. – Adrialsyntax: re
above 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. – Ehrlichsudo hg rm .*
doesn't work. I getabort: .. not under root
which 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_clean
utility, but I getundouble . failed
. Very frustrating. – Adrialsudo hg rm ._*
but it tells menot removing ._*: file is untracked
, yet when I gethg manifest
I see plenty of._
files! – Adrialhg rm .*
is not recursively traveling through directories. Is there a way to make it do this? – Adrialfind . -name "._*" |xargs hg rm
– Nabila