Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Local Mercurial Ignore File

Tags:

mercurial

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?

like image 204
Lieven Cardoen Avatar asked Oct 08 '12 13:10

Lieven Cardoen


People also ask

How do you ignore a file in Heartgold?

Use a local . hgignore which you do not commit, and add whatever you want to it, placing . hgignore first.

What is hgignore file?

The . hgignore file sits in the working directory, next to the . hg folder. It is a file versioned as any other versioned file in the working directory, which is used to hold the content of the ignore patterns that are used for any command operating on the working directory.


2 Answers

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.

like image 95
Christophe Muller Avatar answered Dec 15 '22 09:12

Christophe Muller


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

like image 44
David Levesque Avatar answered Dec 15 '22 10:12

David Levesque