Is it better to hg forget or ignore? - mercurial

I have some binary files that I don't need to commit. I need them for local. Should I do hg forget binary-folder/ or add this line to .hgignore?
glob:binary-folder/*
Which one is better?
Thanks.

The following quote is from this mailing list post by Martin Geisler.
A file can be tracked or not, you use 'hg add' to track a file and 'hg
remove' or 'hg forget' to un-track it. Using 'hg remove' without flags
will both delete the file and un-track it, 'hg forget' will simply
un-track it without deleting it.
Un-tracked files show up with a question mark in 'hg status', unless
they are matched by the .hgignore file. So when you 'hg forget' a file,
it will typically show up as un-tracked in 'hg status', unless you have
a line in your .hgignore that matches said file.
Tracked files are never affected by the .hgignore file.
For your case, apparently ignore would be preferred.

Related

Mercurial - cannot commit merge with missing files error

I have done a 'hg merge' however when I attempt to do a 'hg commit -m "my msg.." I get the following error message :
abort: cannot commit merge with missing files
Can anyone explain how to fix this to allow the commit go through?
Try hg status and look for files in state ! (missing).
The cause is that one of the files which is part of the merge has been deleted. Undelete the file and try again.
Heres my approach
hg status will tell you what files are missing. Then you can either restore the file from somewhere
OR type in hg remove <path/name of missing file>
THEN commit. Your repo will be sane again, darwin willing.
If you are using TortoiseHG, click in View/Commit. It will show you files in state ! (missing).
Right click on the file and choose Revert (undelete the file) and commit.

How to tell mercurial to 1. Discard local file 2. Use remote file

Sometimes I can't seem to be able to track the merge conflicts.
I need a command that allows me to discard one of my uncommitted files and then update it with the remote copy.
I tried hg revert myfile followed by hg pull , hg commit
but it still won't let me merge or commit.
It keeps telling me to fix unresolved conflict first.
You might need to let Mercurial know that you have resolved the conflict, using hg resolve. From the man page:
hg resolve [OPTION]... [FILE]...
redo merges or set/view the merge status of files
Merges with unresolved conflicts are often the result of non-interactive
merging using the "internal:merge" configuration setting, or a command-
line merge tool like "diff3". The resolve command is used to manage the
files involved in a merge, after "hg merge" has been run, and before "hg
commit" is run (i.e. the working directory must have two parents). See "hg
help merge-tools" for information on configuring merge tools.
The resolve command can be used in the following ways:
- "hg resolve [--tool TOOL] FILE...": attempt to re-merge the specified
files, discarding any previous merge attempts. Re-merging is not
performed for files already marked as resolved. Use "--all/-a" to select
all unresolved files. "--tool" can be used to specify the merge tool
used for the given files. It overrides the HGMERGE environment variable
and your configuration files. Previous file contents are saved with a
".orig" suffix.
- "hg resolve -m [FILE]": mark a file as having been resolved (e.g. after
having manually fixed-up the files). The default is to mark all
unresolved files.
- "hg resolve -u [FILE]...": mark a file as unresolved. The default is to
mark all resolved files.
- "hg resolve -l": list files which had or still have conflicts. In the
printed list, "U" = unresolved and "R" = resolved.
Note that Mercurial will not let you commit files with unresolved merge
conflicts. You must use "hg resolve -m ..." before you can commit after a
conflicting merge.
Here's how you pick up the version of the file from the server.
When you "hg pull", all changes from the server come into your copy of the repository. You can get the contents of a file in any revision using:
hg cat -r <rev> <file>
Use that to overwrite the local file, and commit.

abort: untracked file in working directory differs from file in requested revision: '.hgignore'

I am trying to pull some files and directories and I am having the following messages:
When I look in my repository I can see that the files have been downloaded but all contains _ as prefix, and even the names of files and folders contain _
requesting all changes
adding changesets
adding manifests
adding file changes
added 1094 changesets with 4304 changes to 1071 files abort:
untracked file in working directory differs from file in requested revision: '.hgignore' [command interrupted]
What is wrong?
I think you have created a .hgignore in your working directory without adding it to the repository (hg add). This file is "untracked".
Someone else, from another clone, has added this file too, committed and pushed it. Now, when you try to update your working directory, Mercurial try to add this file but sees a file with the same name in your working directory which is untracked and different.
There's two solution to your problem :
Backup your .hgignore file, do the update and add the differences from the backup if necessary
Add your own file to the repository with hg add, then re-run the update. It will maybe be necessary to commit the file prior to the update.
I'll advise using the first solution.
When you say the files in the repository have _ as a prefix, you're looking down inside the .hg directory aren't you? That's the data store for Mercurial itself and the files in there are revlogs, not your files. Outside of .hg you'll have a working directory where the files are the actual files you expect. You're not getting one of those now because hg update is refusing to update the working directory because doing so would overwrite your uncomitted .hgignore file.
What exact command are you running? It looks like it's doing a hg pull followed by an hg update so I'd guess hg clone but if you already have a .hgignore lying around that's not the right command to use. If instead you're using hg pull -u or hg fetch you should just use hg pull instead to get the changesets. Then you can:
hg add .hgignore # add the hg ignore file you already have that's untracked
hg commit -m .hgignore # commit the .hgignore file you just added
hg merge # merge your new commit (.hgignore) with the changesets you just pulled down.

Can Mercurial use .hgignore to forget files?

I forget to place the correct .hgignore into my project and am now confronted with many useless files in my repository. As these files are already under source control .hgignore will not pick em up.
Is there a way for hg to forget all files matched by .hgignore?
filesets awesomeness (requires 1.9):
hg forget "set:hgignore() and not ignored()"
You need to remove that file for it to be ignored.
hg remove -Af myfile
(remove from the revision while leaving a copy on your workspace: or hg forget)
But your Mercurial repository won't "forget" those same files in the previous revisions.
Removing a file does not affect its history.
It is important to understand that removing a file has only two effects.
It removes the current version of the file from the working directory.
It stops Mercurial from tracking changes to the file, from the time of the next commit.
Removing a file does not in any way alter the history of the file.
Another way, when you have a lot of extra files you need now to ignore is:
remove them (from the file system, not with an hg command, but with an OS 'rm' command)
hg addremove (warning, it will add currently non-committed files, but it will hg remove all the other files you just rm'ed)
See How to forget all removed files with Mercurial for more.
I don't think hg can do it out of box.
But it's pretty easy to roll your own. hgignore entries are regexp or glob, so you can just go through the entries and find the matching files/dirs and do "hg remove" on them.
For hgignore parsing/matching, if you use python you can just call the functions in hg's ignore.py.
Maybe someone can write an extension for this.
This is what I did for each of the directories mentioned in .hgignore
for /f "delims=" %i in ('dir bin /ad/s/b') do hg forget %i/
And for files
for /f "delims=" %i in ('dir *.user /s/b') do hg forget %i
DISCLAIMER:
I don't know if it will work on non-windows OS or not.
Idan K's solution is great. I added an alias to my global mercurial.ini because I can't remember the command.
[alias]
forgetignored = forget "set:hgignore() and not ignored()"

For Mercurial (Hg), why the file .hgignore cannot be ignored?

I have these in the proj/.hgignore:
syntax: glob
log/*
*~
*.orig
dump/*
*.hgignore
.hgignore
tmp/*
but for some reason, when I do an hg st or hg com, the file .hgignore still shows up to be modified or to be committed. So the .hgignore cannot be ignored? There might be particulars in my folder that my team didn't want to ignore but I do. So I don't want to commit this file.
Chris has it in the comment: you've probably already added your .hgignore file, and an add overrides the .hgignore. You need to hg forget .hgignore and hg commit and then you'll find your file is ignored.
Thats said, most people put the .hgignore file into the repo for a reason -- so that the next person to clone doesn't accidentally commit all of their log/temporary files.
I think you're looking for this:
https://www.mercurial-scm.org/wiki/TipsAndTricks#Ignore_files_in_local_working_copy_only
The overall .hgignore file is necessary to ignore anything, and so you can't exclude it.