Mercurial,停止版本控制缓存目录但保留目录

发布于 2024-10-16 10:03:57 字数 409 浏览 3 评论 0 原文

我有一个 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

旧时模样 2024-10-23 10:03:57

好吧,如果没有其他办法,你总是可以要求 Mercurial 忘记所有内容,然后在提交之前恢复为空:

这是我重现它的方法,首先创建初始存储库:

hg init
md app
md app\tmp
echo a>app\empty
echo a>app\tmp\empty
hg commit -m "initial" -A

然后添加一些我们稍后想要的文件摆脱:

echo a >app\tmp\test1.txt
echo a >app\tmp\test2.txt
hg commit -m "adding" -A

然后忘记我们不想要的文件:

hg forget app\tmp\*
hg status                     <-- will show all 3 files
hg revert app\tmp\empty
hg status                     <-- now empty is gone
echo glob:app/tmp>.hgignore
hg commit -m "ignored" -A

请注意,.hgignore 所做的一切都是为了防止 Mercurial 在 addremovecommit 期间发现新文件 - 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:

hg init
md app
md app\tmp
echo a>app\empty
echo a>app\tmp\empty
hg commit -m "initial" -A

Then add some files we later want to get rid of:

echo a >app\tmp\test1.txt
echo a >app\tmp\test2.txt
hg commit -m "adding" -A

Then forget the files we don't want:

hg forget app\tmp\*
hg status                     <-- will show all 3 files
hg revert app\tmp\empty
hg status                     <-- now empty is gone
echo glob:app/tmp>.hgignore
hg commit -m "ignored" -A

Note that all .hgignore does is to prevent Mercurial from discovering new files during addremove or commit -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 file empty inside will not be ignored, or removed, since I have explicitly asked Mercurial to track it.

‘画卷フ 2024-10-23 10:03:57

至少理论上(我现在没有时间尝试), 模式匹配应该与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 like hg forget -X empty while in the directory (-X means "exclude").

You may want to consider using .hgignore, of course.

忆梦 2024-10-23 10:03:57

因为你只需要做一次,我就这样做:

find app/tmp -type f | grep -v empty | xargs hg forget
hg commit

从那时起,只需将其放入你的“.hgignore”中

^app/tmp

Since you only need to do it once I'd just do this:

find app/tmp -type f | grep -v empty | xargs hg forget
hg commit

from then on just put this in your `.hgignore'

^app/tmp
溺ぐ爱和你が 2024-10-23 10:03:57

Mercurial 内置了对 globbing 和 regexes 的支持,如 python 正则表达式 实现。

这应该适合你:

hg forget "re:app/tmp/.*(?<!/empty)$"

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:

hg forget "re:app/tmp/.*(?<!/empty)$"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文