我有一个 Mercurial 版本控制下的 CakePHP 项目。现在,app/tmp
目录中的所有文件都正在进行版本控制,并且这些文件始终在变化。
我不想对这些文件进行版本控制。
我知道我可以通过运行 hgforgetapp/tmp/*
来停止,
但这也会忘记文件结构。我想保留它。
现在我知道 Mercurial 不会对目录进行版本控制,而只会对文件进行版本控制,但是 CakePHP 人员也足够聪明,可以在每个空目录中放置一个名为 empty
的空文件(我猜是因为这个原因)。
所以我想做的是告诉 Mercurial 忘记 app/tmp
下的每个文件,除了名称完全为空的文件。
为此,命令是什么?
I have a CakePHP project under Mercurial version control. Right now all the files in the app/tmp
directory are being versioned, which are always changing.
I do not want to version control these files.
I know I can stop by running hg forget app/tmp/*
But this will also forget the file structure. Which I want to keep.
Now I know that Mercurial doesn't version directories, just files, but the CakePHP folks were also smart enough to put an empty file called empty
in every empty directory (I am guessing for this reason).
So what I want to do is tell Mercurial to forget every file under app/tmp
except files whos name is exactly empty.
What would the command be for this?
发布评论
评论(4)
好吧,如果没有其他办法,你总是可以要求 Mercurial 忘记所有内容,然后在提交之前恢复为空:
这是我重现它的方法,首先创建初始存储库:
然后添加一些我们稍后想要的文件摆脱:
然后忘记我们不想要的文件:
请注意,
.hgignore
所做的一切都是为了防止 Mercurial 在addremove
或commit 期间发现新文件 - A,如果您明确跟踪与忽略过滤器匹配的文件,Mercurial 仍会跟踪这些文件的更改。
换句话说,即使我要求 Mercurial 忽略上面的
app/tmp
,内部的文件empty
也不会被忽略或删除,因为我已经明确要求 Mercurial 跟踪它。Well, if nothing else works, you can always just ask Mercurial to forget everything, and then revert
empty
before committing:Here's how I reproduced it, first create initial repo:
Then add some files we later want to get rid of:
Then forget the files we don't want:
Note that all
.hgignore
does is to prevent Mercurial from discovering new files duringaddremove
orcommit -A
, if you have explicitly tracked files that match your ignore filter, Mercurial will still track changes to those files.In other words, even though I asked Mercurial to ignore
app/tmp
above, the fileempty
inside will not be ignored, or removed, since I have explicitly asked Mercurial to track it.至少理论上(我现在没有时间尝试), 模式匹配应该与
hg忘记
命令一起使用。因此,您可以在目录中执行类似hgforget-Xempty
的操作(-X
表示“排除”)。当然,您可能需要考虑使用 .hgignore。
At least theoretically (I don't have time to try it right now), pattern matching should work with the
hg forget
command. So, you could do something likehg forget -X empty
while in the directory (-X
means "exclude").You may want to consider using .hgignore, of course.
因为你只需要做一次,我就这样做:
从那时起,只需将其放入你的“.hgignore”中
Since you only need to do it once I'd just do this:
from then on just put this in your `.hgignore'
Mercurial 内置了对 globbing 和 regexes 的支持,如 python 正则表达式 实现。
这应该适合你:
Mercurial has built-in support for globbing and regexes, as explained in the relevant chapter in the mercurial book. The python regex implementation is used.
This should work for you: