Mercurial hg status displaying ignored files

北慕城南 提交于 2019-12-04 06:15:48

Your regexp syntax is wrong. You have this:

syntax:regexp
^target*$

which means "ignore anything beginning with target and ending with an asterisk

Which fails to ignore these:

Core/target/classes/META-INF/MANIFEST.MF
Core/target/classes/xxx/yyy/zzz/X.class

for two reasons -- they begin with Core/ not target and they don't end with an asterisk.

What you probably meant was this:

syntax:regexp
^.*/target/.*$

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:

syntax:regexp
/target/

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.

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!

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 the addremove 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 the addremove command (which might be set in any of the possible Mercurial configuration files):

$ hg st
# no output, as expected
$ chmod 000 .hgignore
$ hg addremove # with '-X "**/target/**"' set as default somewhere
$ hg commit 
nothing changed  
$ hg st
? Core/target/Core-0.0.1-SNAPSHOT-tests.jar
? Core/target/Core-0.0.1-SNAPSHOT.jar
...

hg fails in reading the ignore file and thus does not know that the target stuff should be ignored. A corresponding warning from hg would be helpful here.

This question has been updated in response to Jerome's comment.

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:

  1. Make sure your .hgignore file says what you want it to and that all the files turning up in the hg status are the ones you want to ignore.
  2. Add all the files to be ignored. hg addremove doesn't work because it does honour the hgignore contents, so I used Eclipse's hg plugin and did each file manually (well, I selected them all and Eclipse applied the add to them all individually).
  3. 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

  4. 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 :( )

  5. commit

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 :)

? 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

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!)

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.

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