4

Situation

$ cat .hgignore
.hgignore

$ hg status
M file1
M file2
M src/project.xml

I don't want to track the project.xml so I run

echo "project.xml" >> .hgignore

and the result is

$ cat .hgignore
.hgignore
project.xml

$ hg status
M .hgignore
M file1
M file2
M src/project.xml

So the .hgignore is now as modified even though it shouldn't be tracked and nothing happend with the project.xml. What does this mean?

user219882
  • 15,274
  • 23
  • 93
  • 138
  • Are you sure that the `src/project.xml` wasn't already in the files tracked by `hg`? – Atropo Mar 29 '13 at 08:38
  • @Atropo It was... But I thought putting it into `.hgignore` will remove it from there. – user219882 Mar 29 '13 at 08:46
  • 1
    Maybe this question can help you: [How to stop tracking a file without deleting it on mercurial](http://stackoverflow.com/questions/8482538/how-to-stop-tracking-a-file-without-deleting-the-file-on-mercurial). – Atropo Mar 29 '13 at 08:50

1 Answers1

15

You wrote:

"M src/project.xml"

which means that src/project.xml is under version control. A file already under version control cannot be ignored! The .hgignore file is for ignoring files that are untracked (status will show a "?").

You have two solutions to ignore your file:

  1. You can either "hg forget" the file, the opposite of "hg add" (i.e., telling Mercurial not to track this file anymore), or
  2. You can use the ”-X” option as a default for status/diff/commit in your .hg/hgrc configuration file, e.g.,

    [defaults]
    status = -X <file>
    diff = -X <file>
    commit = -X <file>

which will tell hg not to include this file in the use of status, diff, and commit.

Christophe Muller
  • 4,850
  • 1
  • 23
  • 31
  • 3
    I think the `hg forget` definitely is the better option here. A VCS should not just silently ignore a modified file under version control, that WILL lead to trouble in the future when you forget about this and expect hg to just track changes to the file without thinking about it. – chris Mar 29 '13 at 09:59