如何确定哪个规则导致文件在Mercurial中被忽略? [英] How to determine which rule is causing a file to be ignored in Mercurial?

查看:60
本文介绍了如何确定哪个规则导致文件在Mercurial中被忽略?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Mercurial当前正在忽略一个文件,我认为不应忽略该文件. .hgignore文件很大,经过粗略的阅读之后,不清楚哪个规则是罪魁祸首.

Mercurial is presently ignoring a file which I believe shouldn't be ignored. The .hgignore file is remarkably large, and after a cursory read-through it's not obvious which rule(s) is/are the culprit.

是否有办法让Mercurial告诉我.hgignore中的哪些规则(如果有)与文件匹配?

Is there a way to get Mercurial to tell me which rules in the .hgignore (if any) match a file?

推荐答案

您不能开箱即用,但是可以为此编写Mercurial扩展.

You can't do this out of the box, but you can write Mercurial extension for this.

我编写了扩展名 hg被忽略,它可以向您显示.hgignore中的哪些规则匹配指定的文件夹或文件.

I've written extension hg-isignored that can show you which rules in .hgignore match specified folder or file.

安装

在某个地方(即~/.hgrc.d/hg-isignored文件夹中)克隆扩展源:

Clone extension source somewhere, i.e. in ~/.hgrc.d/hg-isignored folder:

hg clone https://hg@bitbucket.org/rpeshkov/hg-isignored ~/.hgrc.d/hg-isignored

.hgrc文件的扩展名部分中添加扩展名:

Add extension in extensions section of your .hgrc file:

[extensions]
isignored=~/.hgrc.d/hg-isignored/hg-isignored.py

现在Mercurial将能够使用由扩展实现的isignored命令.

Now Mercurial will be able to use isignored command that's implemented by extension.

用法

在Mercurial存储库中时,运行命令hg isignored PATH,而不是PATH插入要检查的文件夹或文件,即hg isignored readme.txt.扩展程序将告诉您是否忽略了指定的PATH,并显示您使用的规则.

While you're in Mercurial repository, run command hg isignored PATH, where instead of PATH insert folder or file that you want to check, i.e. hg isignored readme.txt. Extension will tell you if specified PATH is ignored and will show you used rule.

测试

初始化

[~/hgtest]% hg init

否.hgignore

No .hgignore

[~/hgtest]% touch readme.txt
[~/hgtest]% hg st  
? readme.txt
[~/hgtest]% hg isignored readme.txt
abort: .hgignore file not found

添加了.hgignore

Added .hgignore

[~/hgtest]% echo "syntax: glob" > .hgignore
[~/hgtest]% echo "readme.txt" >> .hgignore
[~/hgtest]% hg st
? .hgignore
[~/hgtest]% hg isignored readme.txt
Path 'readme.txt' is ignored by:
relglob:readme.txt

不可忽略的文件

[~/hgtest]% touch readme2.txt
[~/hgtest]% hg isignored readme2.txt
Path 'readme2.txt' is not ignored

忽略文件夹

[~/hgtest]% mkdir build
[~/hgtest]% touch build/keep.txt
[~/hgtest]% echo "build/" >> .hgignore
[~/hgtest]% hg st
? .hgignore
? readme2.txt
[~/hgtest]% hg isignored build
Path 'build' is ignored by:
relglob:build/
[~/hgtest]% hg isignored build/keep.txt
Path 'build/keep.txt' is ignored by:
relglob:build/

忽略文件夹中的所有内容

Ignore everything in folder

[~/hgtest]% echo "syntax: glob" > .hgignore
[~/hgtest]% echo "build/*" >> .hgignore
[~/hgtest]% hg st
? .hgignore
? readme.txt
? readme2.txt
[~/hgtest]% hg isignored build
Path 'build' is not ignored
[~/hgtest]% hg isignored build/keep.txt
Path 'build/keep.txt' is ignored by:
relglob:build/*

这篇关于如何确定哪个规则导致文件在Mercurial中被忽略?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆