I need to ignore all files in whole project tree, versioned by Mercurial, that starts with specific character. Let's say underscore (or it may be some other).
I searched on google a lot, but I cannot find right glob syntax. I found glob expression test environment, where I could try patterns, but nothing works for me.
Consider following project structure:
/function/_backup/file1.php
/function/_backup/file2.php
/function/Class/A.php
/function/Class/_B.php
/_graph/1.jpg
/.hgignore
/.htaccess
/_index.php
/index.php
The only files that I need to propagate to repository are A.php, .htaccess and index.php.
The question is: how should my .hgignore look like?
You should add the following line to .hgignore:
glob:_*
Related
__
Hello everybody,
My hgignore file contains following lines:
syntax:regexp
^data/dyn/.*
^data/config/.*
^data/temp/.*
^data/mediapool
^\.project
^\.buildpath
^\.settings/.*
^nbproject/.*
/\.git/
\.hg_archival.txt
syntax:glob
*.sublime-project
*.sublime-workspace
sftp-config.json
BUT, i want to "unignore" the folder data/dyn/xxx/yyy with it's files inside.
How can i solve my problem?
Many thanks!
Mercurial .hgignore files are a blacklist only. The only way to whitelist something is to blacklist the "outer" group and then hg add what you want not-ignore. Adding something with hg add always trumps ignoring it in .hgignore.
That works great for files, but not so great for directories since you can't add directories. You can add all the files in them, but any new files that land there will be ignored until you add them.
You can try using the "zero-length negative look-ahead" feature of regular expressions, but honestly it's easier to just add the files in that directory.
I added a function to file on an a branch I can't remember. I want to port that function to a different branch. How can I search Mercurial to find it?
I know the name of the function and the file I put it in.
I'm using TortoiseHg, and it's got a search bar at the top. I'm not sure which Mecurial command it's using internally..maybe hg log?
But so far I've got
user('me') and file('glob:class/database.php') and ????('myfunctionname')
Not sure what filter I can use to search diff contents.
Also, I don't really know how those filename patterns work, I seem to have to search from the base; can't I do an exact match on filename, excluding directories?
I believe the grep command is what you're looking for:
hg grep 'myfunctionname' -r "user('me') and file('class/database.php')"
You can match a specific file in the file revset query by specifying its full path. Use **file.extension to find any file.extension anywhere in the repository. See the Mercurial docs on file patterns for more information. They are a little unclear on how to match any file with a specific name anywhere in the repo, however, so you'll probably have to do experiment a little.
When I create a new repository, I can ask TortoiseHG to give me a .hgignore file. Is there a way that I can customise what that file will look like, rather than having to go and get one manually from somewhere every time?
It's an old question, put still popped up as the first result on google, so here is an update:
In the TortoiseHg settings under the tab TortoiseHg users can specify the path of a Repo Skeleton. You can put your predefined .hgignore there, and it will be automatically copied during hg init.
See also:
#3569 Allow user-defined default .hgignore file when creating a new repository
TortoiseHG Docs
Like Tim already said in his comment, apparently it's not possible to do this.
Take a look at the following issue from TortoiseHG's bug tracker:
#966 Include some reasonable defaults in .hgignore on repo creation
Quotes from this link, both by Steve Borho (THG project lead):
This topic comes up on the Mercurial mailing list once a year or so and Matt always shoots it down. There is already support for user level ignore files; one could add these globs to a global file and be done with it.
and:
If a user has files or directories that they always want to ignore, they can add those to a global ignore file without having to introduce any new behaviors in THG.
So putting the things you always want ignored in a user-global ignore file seems to be the only option (even though it's not exactly what you're asking for):
Would like to create some defaults for my .hgignore files in TortoiseHG/Mercurial
(the question that I posted in my comment above)
Global hgignore usage
I've read several posts here about ignoring files in Mercurial but I'm stumped on this one.
I have a couple of .svn files in my repository (I'm using hg for local commits, then pushing to svn). The files are:
Apps\.svn\dir-prop-base
Apps\.svn\entries
I've got several ignore entries in my .hgignore but none of them seem to be covering these two files.
syntax: glob
.svn/*
**/.svn/**.*
syntax: regexp
\.svn\\*
I'm trying a couple of things to see which sticks there. To me, it looks like those files should be ignored twice. The strange thing is that Apps\.svn\all-wcprops is being ignored. Clearly I'm missing something. I'm checking whether the files are ignored by opening a new status window using TortoiseHg. I can't detect any difference between that and hg status.
Oben pointed me in the right direction. He declined making an answer, so here it is:
The files that you want to ignore can't be in an Add state when you are editing the ignore file (since Add takes precedence over Ignore apparently). So my solution was to do hg revert, edit the ignore file, then use hg status [directory] -i to see which files in the target directory would be ignored. Repeat until all the correct files are ignored, then use hg add.
syntax: regexp
^.*\.svn/dir-prop-base$
works for me.
The following simple .hgignore works fine for me to ignore all .svn folders (on Windows, hg 1.7):
syntax: glob
.svn
Can anyone tell me the .hgignore pattern to track one specific file in a directory and to ignore everything else?
I have a "media" directory which contains a "default.png", for obvious purposes, and the rest of the directory will hold user media. We want hg to ignore everything in the media directory excepting the default file.
Try:
syntax: regex
^media/.*
or (leave it in the default glob and do)
media/**
and then manually hg add media/default.png.
In mercurial (unlike in CVS) you can add files that match your ignore patterns and they work fine. So ignore broadly and hg add what you want tracked.
syntax: regex
^media/(?!default.png$)
almost the same as John Mee's but matches to the end of the line, instead of anything that starts with default.png.
if you wanted to allow any .c file but nothing else, you could use:
^media/(?!.+\.c$)
Summing it up as a BKM (Best Known Method)
Either hgignore everything, and then hg add back the few files you want to track.
Or use a pattern such as
syntax: regex
^path/(?!files-that-you-want-not-to-ignore$)
(I just wanted to see the full answer in one place.)
Never mind this seems to work...
syntax: regex
^media/(?!default.png)