11

Is it possible to have a local Mercurial ignore file? Apparently the .hgignore is a file versioned as any other file. Can I have such a file next to the versioned one?

4
  • why don't you want to version it? Oct 8, 2012 at 13:57
  • Because it's for instance a local folder to do some proof of concepts... But you're right, I could just version it. For instance, I have a couple of bat scripts in the root of my project with local paths in it... I do not want these scripts to be versioned. But if everyone has a few of those bat scripts, the ignore file will get stuffed... Oct 8, 2012 at 14:01
  • 1
    Anyway, just wanted to know if it was possible to have a local ignore file. Oct 8, 2012 at 14:02
  • possible duplicate of hg local ignore
    – dimo414
    Jun 10, 2015 at 3:25

3 Answers 3

23

Yes you can configure a local, per-user ignore file. The location and name of this file is defined in the user-specific .hgrc configuration file (usually located in the home directory of the user) under the [ui] section, e.g.:

[ui]
ignore = ~/.myhgignore

This file should be in the same format as the repository-wide .hgignore file.

Reference: http://www.selenic.com/mercurial/hgrc.5.html#ui

1
12

There are several cases here, so depending on the case you'll have different possible solutions:

  1. If the file or directory hasn't been added yet and if there is no .hgignore file, you can:
    • use .hgignore to filter it, and
    • you can commit .hgignore if this is also useful for others (e.g., *.o, etc.) or you can leave the .hgignore as local without commiting/pushing it, and in this case, you can even specify .hgignore in .hgignore as mentioned by msw so that your local version will also be ignored.
  2. If the file or directory hasn't been added yet and if there is an .hgignore file that for some reason you do not want to use (commit and push), you can:
    • declare an untracked ignore file which you will use just like .hgignore except it will stay local. You can declare this untracked ignore file either in your repo .hg/hgrc or you global $HOME/.hgrc (see the UI section doc).
  3. Finally, if the file/directory has been added to the list of tracked files, then you can't filter it with .hgignore: any file that is already committed cannot be ignored! You can either:
    • "hg forget" the file (the opposite of "hg add"), then do as the two first cases, or use the "-X" option as a default for status/diff/commit in your .hg/hgrc configuration file, e.g.,
      [defaults]
      status = -X file1 -X file2
      diff = -X file -X file2
      commit = -X file -X file3
      which will tell hg not to include these files in the use of status, diff, and commit.

Hope it'll help.

1
  • 3
    But DO NOT use forget on files shared across repos. Push's or pulls from your working repo will delete the files on the other end. Apr 10, 2013 at 20:55
1

You can also ignore .hgignore in your local repository:

$ hg clone some_repository
$ cd some_repository
$ cat > .hgignore
syntax: glob
.hgignore
$ touch foo.c bar.c
$ hg status
? foo.c
? bar.c

Note the conspicuous absence of the local .hgignore in the output of hg status.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.