ignoring folders in mercurial

馋奶兔 提交于 2019-11-29 01:01:30

Try it without the slash after the caret in the regexp version.

^test/

Here's a test:

~$ mkdir hg-folder-ignore
~$ cd hg-folder-ignore
~/hg-folder-ignore$ echo '^test/' > .hgignore
~/hg-folder-ignore$ hg init
~/hg-folder-ignore$ mkdir test
~/hg-folder-ignore$ touch test/ignoreme
~/hg-folder-ignore$ mkdir -p srcProject/test/TestManager
~/hg-folder-ignore$ touch srcProject/test/TestManager/dont-ignore
~/hg-folder-ignore$ hg stat
? .hgignore
? srcProject/test/TestManager/dont-ignore

Notice that ignoreme isn't showing up and dont-ignore is.

Nathan Kitchen

You can use zero-width negative look-ahead and look-behind assertions to specify that you want to ignore test only when it's not preceded by srcProject and not followed by TestManager:

syntax: regexp
(?<!srcProject\\)test\\(?!TestManager)

Mercurial uses Python regular expressions, so you can find more info on zero-width assertions in the Python docs: https://docs.python.org/library/re.html#regular-expression-syntax

Both cases worked for me (on linux and windows):

syntax: regexp
^backup/     #root folder
nbproject/   #any folder

or

syntax: glob
./backup/*   #root folder
nbproject/*  #any folder

However, it wasn't before I added a link to .hgignore file to .hgrc file in my repo:

[ui]
ignore = .hg/.hgignore

Also worth mentioning that mercurial ignores files that it is not currently tracking, which are those added before you configured it to ignore them. So, don't be put off by hg status saying some filed are M (modified) or ! (missing) in the folders that you have just added to the ignore list!

Create .hgignore file under root directory of the repository

Now add the following contents in the file .

syntax: glob

bin/**

*.DS_Store

This will remove the bin directory and all the *.DS_Store files from the repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!