Is it possible to have a branch-specific ignore file in mercurial?
It would be handy to have dependencies included in a production branch, but not in a development branch.
Mercurial always uses the checked out .hgignore file. So technically you can have different .hgignore files on different branches, but when you use this scheme, you need to take care that they stay different when you merge between this branches.
When you have only one system where the additional ignore patterns should apply, you can also specify an additional igore file within .hg/hgrc via the ui.ignore setting.
$ cat >> .hg/hgrc << EOF
[ui]
ignore=.hg/production_ignore
EOF
$ cat > .hg/production_ignore << EOF
# example ignore file, uses the same syntax as .hgignore
syntax: glob
*.swp
*.~
EOF
Related
I need to set up Mercurial HG in order to always take local version of a file that matches in a specific folder.
EG: when conflict on /**/dist/ always take local
This because I need to commit some built files.
Thanks in advance
EDIT:
I need to commit some files generated by some processors (libsass, webpack), it depends on a temporary unavailability of my build-system. So, I removed these files from the hgignore. Now, the problem that I'm having is on Mercurial conflicts on these generated files. I want automate the merge-resolving using the local version of these files. similar to: How to keep the local file or the remote file during merge using Git and the command line? but for Mercurial HG
You can put a merge-pattern in your ~/.hgrc or .hg/hgrc to specify the default tool for a merge for a given file:
[merge-patterns]
**/dist/* = :local
The :local merge tool will prioritize the local version. See hg help merge-tools for a full list of internal merge tools. Note that using the --tool option during a merge will override this choice; however, setting the ui.merge option to define your default merge tool will not.
The **/dist/* pattern may or may not be what you need. Please adjust it to your needs (and note that regular expression patterns are also available for additional flexibility if required).
Alternatively, you can also automatically resolve these files after the merge, e.g. with:
hg resolve --tool :local $(hg files -I '**/dist/*')
Or, if the list of files is too large to fit on the command line:
hg files -0 -I '**/dist/*' | xargs -0 hg resolve --tool :local
I use Mercurial Queues to work with patches.
There was no .hgignore initially.
I'm not sure if I first created an MQ patch and then created my .hgignore or the other way round.
(By "creating a patch" I mean hg qnew patch_name -m "...")
Anyway, I made some changes to .hgignore after I created the MQ patch.
When I did hg qrefresh; hg export qtip I got the changed contents of .hgignore also in my patch.
So, tried adding an .hgignore entry to .hgignore itself. But that didn't work. The changes persisted.
So, I tried hg forget .hgignore and this made a bigger mess. It nows shows that I deleted .hgignore in my patch. Like so:
--- a/.hgignore
+++ /dev/null
- all
- the lines of .hgignore
- the lines of .hgignore
How do I resolve this problem?
I just want .hgignore to be part of my local repo and help in not tracking some files.
.hgignore is designed to be tracked by Mercurial (doc). The standard way to ignore files in local clone only is to use ui.ignore setting:
# .hg/hgrc
[ui]
ignore = /path/to/repo/.hg/hgignore
If you have multiple local ignore files then you can write
[ui]
ignore.first = /path/to/repo/.hg/firstignore
ignore.second = /path/to/repo/.hg/secondignore
Additional global ignore files can be configured in this way:
[ui]
ignore.first = /path/to/repo/.hg/firstignore
ignore.second = /path/to/repo/.hg/secondignore
ignore.third = ~/thirdignore
All settings live in hgrc file. More details here:
hgrc file location: doc
ui.ignore setting reference: doc
about .hgignore files: doc
original recipe: Tips And Tricks
In Hg, how to ignore a directory recursively if some of its subdirectories and contained files are already tracked? I'd like to keep them in my file system but don't version control them. I don't want to remove the directory from the file system.
You can use hg forget dir_name/ to stop tracking directory called dir_name recursively.
More info on hg forget:
hg forget [OPTION]... FILE...
forget the specified files on the next commit
Mark the specified files so they will no longer be tracked after the next
commit.
This only removes files from the current branch, not from the entire
project history, and it does not delete them from the working directory.
To undo a forget before the next commit, see "hg add".
Examples:
- forget newly-added binary files:
hg forget "set:added() and binary()"
- forget files that would be excluded by .hgignore:
hg forget "set:hgignore()"
Returns 0 on success.
options:
-I --include PATTERN [+] include names matching the given patterns
-X --exclude PATTERN [+] exclude names matching the given patterns
--mq operate on patch repository
I have a Mercurial repository with several subrepos. Is there a possibility to only define a general .hgignore-File (e.g. to ignore object-files) both in the main repository and, optionally a specialized one in the sub-repositories?
There is not enough information in the manual. Specifying a .hgignore file with
[ui]
ignore = .hgignore
to .hgrc in my home-directory also does not work.
Any ideas?
A .hgignore file in each subrepo would serve as the specialized one for that subrepo. Then you can use the main repo's .hgignore as the main one by including this in each subrepo's hgrc file:
[ui]
ignore.main = \absolute\path\to\mainrepo\.hgignore
The reason why doing ignore = .hgignore didn't work for you in your global .hgrc (and won't in repo hgrc) is that having simply .hgignore is a relative file path and its resolution to an absolute path depends on the current working directory used when invoking hg. Examples:
If you're in \repos\main\ and invoke hg st, it will look for \repos\main\.hgignore. Same thing if you invoke hg st -R nested, because the current working directory is still the same.
But if you were in \repos\main\nested\ and then invoked hg st, the config would now be looking at \repos\main\nested\.hgignore.
If you want to specify a global .hgignore that is in your home directory, you would need to specify it with a non-relative path (or at least much less relative):
[ui]
ignore = ~\.hgignore
I have been thinking that it sure would be nice to have a command like "hg ignore" that would automatically add all untracked files to the .hgignore file.
Manually editing the .hgignore file is powerful, but when I am frequently creating new repositories it would be nice to be able to add only the files I want and then do an hg ignore to automatically have Mercurial ignore any others.
Does anyone know of any extensions that do this?
Try this once you've added all the files you need:
hg stat --unknown --no-status >> .hgignore
You can create a command to automatically generate your .hgignore using an alias. On a Unix-like system, add the following lines to your .hg/hgrc (or one of Mercurial's other configuration files):
[alias]
ignore = !echo 'syntax: glob' >> $(hg root)/.hgignore && \
$HG status --unknown --no-status >> $(hg root)/.hgignore
This will give you a hg ignore command that will populate the .hgignore file with all currently unknown files, thus turning them into ignored.
On Windows, the syntax for the alias is:
[alias]
ignore = !echo syntax: glob > .hgignore && "%HG%" status --unknown --no-status -X .hgignore >> .hgignore
On Windows, you must run it in the root directory of the repository, otherwise the .hgignore file will be created in the current directory, which is probably not what you want.
The ! syntax in aliases is new in Mercurial 1.7. In earlier versions you can add
[alias]
ignore = status --unknown --no-status
and then redirect the output of this command to the .hgignore file yourself:
hg ignore >> .hgignore
You will then also need to take care of adding a syntax: glob line, if necessary (the default syntax is regular expressions).