Mercurial hg 状态显示被忽略的文件
谁能告诉我为什么 Mercurial 显示“hg status”命令的忽略文件?
这里确认了 Mercurial 确实忽略了这些文件:
$ hg addremove
$ hg commit
nothing changed
现在,看看状态输出。我在上面几行之后立即运行了这个。 (打印输出是部分的,可识别的文本被删除)
$ hg status
? Core/target/Core-0.0.1-SNAPSHOT-tests.jar
? Core/target/Core-0.0.1-SNAPSHOT.jar
? Core/target/classes/META-INF/MANIFEST.MF
? Core/target/classes/xxx/yyy/zzz/X.class
? Core/target/classes/xxx/yyy/zzz/XBackup.class
? Core/target/classes/xxx/yyy/zzz/XBackupInput.class
? Core/target/classes/xxx/yyy/zzz/XBackupOutput.class
? Core/target/classes/xxx/yyy/zzz/XImpl$GetResultsAndStatistics.class
? Core/target/classes/xxx/yyy/zzz/XImpl$MonitoringMode.class
? Core/target/classes/xxx/yyy/zzz/XImpl$UpdateMode.class
? Core/target/classes/xxx/yyy/zzz/XImpl.class
? Core/target/classes/xxx/yyy/zzz/XIsFullException.class
? Core/target/classes/xxx/yyy/zzz/XSource.class
? Core/target/classes/xxx/yyy/zzz/XUsageException.class
? Core/target/classes/xxx/yyy/zzz/CheckResults.class
? Core/target/classes/xxx/yyy/zzz/Noise.class
? Core/target/classes/xxx/yyy/zzz/core/DateTimeGenerator$TemporalMeasure.class
? Core/target/classes/xxx/yyy/zzz/core/DateTimeGenerator.class
? Core/target/classes/xxx/yyy/zzz/core/LoggingConfigurator.class
? Core/target/classes/xxx/yyy/zzz/core/ManagedIterator.class
? Core/target/classes/xxx/yyy/zzz/core/NetworkUtils.class
? Core/target/classes/xxx/yyy/zzz/core/StackTraceUtils.class
? Core/target/classes/xxx/yyy/zzz/core/Summarisable.class
? Core/target/classes/xxx/yyy/zzz/core/TimingUtils.class
? Core/target/classes/xxx/yyy/zzz/core/XMLStaticStringUtils.class
? Core/target/classes/xxx/yyy/zzz/core/Zipper.class
...
状态打印输出中显示了大约一千行这些被忽略的文件;这是一些严重的废话。
我怎样才能摆脱这个?
谢谢
更新:
这是我的 .hgignore 文件。
syntax:glob
.metadata*
syntax:regexp
^target.*$
^[^/]*/target.*$
^[^/]*/[^/]*/target.*$
^bin.*$
^[^/]*/bin.*$
^[^/]*/[^/]*/bin.*$
更新:
稍微修改了正则表达式 * -> .*
Can anyone tell me why mercurial is displaying ignored files for the 'hg status' command?
Here's the confirmation that mercurial is indeed ignoring the files:
$ hg addremove
$ hg commit
nothing changed
Now, have a look at the status output. I ran this immediately after the lines above. (Prinout is partial, with identifiable text removed)
$ hg status
? Core/target/Core-0.0.1-SNAPSHOT-tests.jar
? Core/target/Core-0.0.1-SNAPSHOT.jar
? Core/target/classes/META-INF/MANIFEST.MF
? Core/target/classes/xxx/yyy/zzz/X.class
? Core/target/classes/xxx/yyy/zzz/XBackup.class
? Core/target/classes/xxx/yyy/zzz/XBackupInput.class
? Core/target/classes/xxx/yyy/zzz/XBackupOutput.class
? Core/target/classes/xxx/yyy/zzz/XImpl$GetResultsAndStatistics.class
? Core/target/classes/xxx/yyy/zzz/XImpl$MonitoringMode.class
? Core/target/classes/xxx/yyy/zzz/XImpl$UpdateMode.class
? Core/target/classes/xxx/yyy/zzz/XImpl.class
? Core/target/classes/xxx/yyy/zzz/XIsFullException.class
? Core/target/classes/xxx/yyy/zzz/XSource.class
? Core/target/classes/xxx/yyy/zzz/XUsageException.class
? Core/target/classes/xxx/yyy/zzz/CheckResults.class
? Core/target/classes/xxx/yyy/zzz/Noise.class
? Core/target/classes/xxx/yyy/zzz/core/DateTimeGenerator$TemporalMeasure.class
? Core/target/classes/xxx/yyy/zzz/core/DateTimeGenerator.class
? Core/target/classes/xxx/yyy/zzz/core/LoggingConfigurator.class
? Core/target/classes/xxx/yyy/zzz/core/ManagedIterator.class
? Core/target/classes/xxx/yyy/zzz/core/NetworkUtils.class
? Core/target/classes/xxx/yyy/zzz/core/StackTraceUtils.class
? Core/target/classes/xxx/yyy/zzz/core/Summarisable.class
? Core/target/classes/xxx/yyy/zzz/core/TimingUtils.class
? Core/target/classes/xxx/yyy/zzz/core/XMLStaticStringUtils.class
? Core/target/classes/xxx/yyy/zzz/core/Zipper.class
...
There's something like a thousand lines of these ignored files showing in the status printout; that's some serious guff.
How can I get rid of this?
Thanks
UPDATE:
Here's my .hgignore file.
syntax:glob
.metadata*
syntax:regexp
^target.*$
^[^/]*/target.*$
^[^/]*/[^/]*/target.*$
^bin.*$
^[^/]*/bin.*$
^[^/]*/[^/]*/bin.*$
UPDATE:
Modified regexps a wee bit * -> .*
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您的正则表达式语法错误。你有这样的:
这意味着“忽略以目标开头并以星号结尾的任何内容”
它无法忽略这些:
有两个原因 - 它们以
Core/
开头而不是target
并且它们不以星号结尾。您可能的意思是:
它与其中包含
/target/
的任何内容匹配(注意它是.**
中的 code> 用于 glob 样式),但是^
和$
仅用于根正则表达式,而您不希望这样做。它已扎根 - 您想在字符串中的任何位置找到它,所以只需这样做:所有这一切的线索是文件被标记为
?
这意味着不被忽略并且不被添加< /strong>,如果它们被忽略,那么如果不将--ignored
添加到状态命令中,您将根本看不到它们。Your regexp syntax is wrong. You have this:
which means "ignore anything beginning with target and ending with an asterisk
Which fails to ignore these:
for two reasons -- they begin with
Core/
nottarget
and they don't end with an asterisk.What you probably meant was this:
which matches anything that has
/target/
in it (notice it's.*
in a regexp*
is for glob style). However the^
and$
only serve to root your regex and you don't want it rooted -- you want to find it anywhere in the string, so just do this:The clue in all this was that the files were marked with
?
which means not ignored and not added, if they were ignored you wouldn't see them at all without adding--ignored
to the status command.我遇到了类似的问题,因为我更改了某些文件的字母大小写。所以之前我得到了名为“sitenav.ext”的文件,将其重命名为“siteNav.ext”并开始遇到同样的问题 - 当我尝试“hg st”时,我得到了“?siteNav.ext”。
修复很容易
重命名为“_siteNav.ext”,
添加删除,
犯罪,
重命名回“siteNav.ext”,
添加删除,
提交->利润!
I got similar issue because I changed letter case for some files. So previously I got file called "sitenav.ext", renamed it to "siteNav.ext" and started to have same sort of issues - when I tried to "hg st" I got "? siteNav.ext".
Fix was easy
rename to "_siteNav.ext",
addremove,
commit,
rename back to "siteNav.ext",
addremove,
commit -> profit!
正如 Jerome 在问题中评论的那样,提供您的配置可能会有所帮助。
造成您的问题的一个(诚然很奇怪)原因可能是
.hgignore
文件与排除addremove
命令的默认值。我可以通过撤销忽略文件的任何读取权限并使用
-X "**/target/**"
作为addremove
命令的默认选项来重现您的情况(可以在任何可能的 Mercurial 配置文件中设置):hg
无法读取忽略文件,因此不知道应该忽略目标内容。来自hg
的相应警告在这里会很有帮助。此问题已针对 Jerome 的评论进行了更新。
As commented by Jerome in the question, providing your config might help.
One (admittedly strange) reason for your problem could be a permission issue with the
.hgignore
file combined with exclude defaults for theaddremove
command.I could reproduce your situation by revoking any read permission from the ignore file and by using
-X "**/target/**"
as a default option for theaddremove
command (which might be set in any of the possible Mercurial configuration files):hg
fails in reading the ignore file and thus does not know that the target stuff should be ignored. A corresponding warning fromhg
would be helpful here.This question has been updated in response to Jerome's comment.
非常感谢大家对此的帮助。我还没有找到问题的答案,但我确实找到了解决问题的方法。所以我假设在修改 hgignore regexps Mercurial 时的某个时候,它会感到困惑并损坏它的内部数据......或者其他什么。我不太了解内部情况,无法知道这可能是什么。
无论如何,如果您发现自己处于同一条船上,这就是我所做的:
恢复所有添加的文件。我使用了以下内容,因为我在 Linux 上。 (感谢另一张关于 SO 的单独问题的海报 - 不幸的是我现在找不到了)
hg 状态-an0 | xargs -0 hg revert
重复上述步骤,直到不再起作用。就我而言,有时连续恢复多达 3 次! (虽然不知道它实际上在做什么:( )
您现在应该不再在 hg status 输出中看到被忽略的文件,但
我很抱歉,我不知道为什么会这样,或者最初的问题是什么,如果有人这样做,我会非常高兴。有兴趣了解您的想法,
再次感谢大家:)
Many thanks for everyone's help on this. I haven't found an answer to the problem but I did find a workaround that got rid of it. So I'm assuming that at some point when modifying the hgignore regexps mercurial got confused and corrupted it's internal data... or something. I don't know enough internals to know what this could have been.
Anyway, should you find yourself in the same boat, here's what I did:
Revert all added files. I used the following because I'm on linux. (thanks to another poster on a separate question here on SO - which I can now no longer find unfortunately)
hg status -an0 | xargs -0 hg revert
repeat the above step until it no longer works. In my case this was sometimes up to as many as 3 reverts in a row! (No idea what it was actually doing though :( )
You should now no longer see the ignored files in the hg status output.
I'm sorry, I have no idea why this worked, or what the original problem was. If anyone does, I'd be very interested to know your thoughts.
Many thanks again to everyone :)
?并不意味着被忽略。
这只是意味着 Mercurial 没有跟踪该文件。
如果您不想看到它们,只需执行
hg status -mard
即仅显示修改、添加、删除、删除
? does not mean ignored.
It just means that mercurial is not tracking the file.
If you don't want to see them just do
hg status -mard
i.e. only show modified, added, removed, deleted
您的 .hgignore 文件显示“^target”被忽略,但文件位于 Core/target 中。因此,忽略行应该是“target”(不带^)或“^Core/target”。
或者我在这里错过了什么?
(注意:^ 表示正则表达式匹配从路径的开头开始,即仅匹配以 target 开头的路径!)
Your .hgignore file says "^target" is ignored, but the files are in Core/target. So the ignore line should rather be "target" (without the ^) or "^Core/target".
Or am I missing sth here?
(Note: ^ implies that regex matching starts from the beginning of the path, i.e. only paths starting with target would be matched!)
遇到了同样的问题,鲍勃的回答对我有用。
如果您使用 TortoiseHg,您可以在上下文菜单(窗口)中选择“编辑忽略过滤器”来验证和更改您的 .hgignore 设置。
Had the same problem and Bob's answer did the trick for me.
If you are using TortoiseHg you can select "edit ignore filter" in the context menu (windows) to verify and change your .hgignore settings there.