TortoiseHg: Delete files that are ignored - mercurial

I'm using TortoiseHg for mercurial repositories. Of course, I exclude directories, such as
bin
obj
Debug
Release
*.suo
And so on...
Over time, when I open solutions from the repository, these directories get created by Visual Studio. I want to get rid of them because I also keep backups of my hard drive and these directories increase its size, especially the C++ sdf-file!
What I've tried
I tried the purge extension. But this apparently seems to just delete empty directories and has nothing to do with the .hgignore file.
Question: How can I delete all files that are covered by .hgignore?

hg purge deletes untracked files. hg purge --all deletes ignored files as well. Since an ignored directory ignores all the files under it, it will delete that directory.

Related

"hg purge" deleted tracked file

I know it is strange but I was updating my testcases and thought of removing all the untracked files from the testcase so ran hg purge, but apart from deleting untracked file it deleted tracked files for 230+ testcases too.
Is there any way to revert back to original or can I get the files back? These files are on the server so I can get it by pulling it from server, but this is not helpful as I have to update it again.
If you have modified Working Directory ("modified" by any way) you can easy discard changes and return to the state of clean "."-changeset using
hg up -C -r .
And yes, follow-up to #torek, hg purge must not touch tracked files, because, according to it's wiki
extension purges all files and directories not being tracked by
Mercurial in the current repository
but I can see one possible case, why it's may happen. Next para in description shed some light on topic
With the --all option, it will also remove ignored files
(and some pure speculation below...)
If you had files in .hgignore and added these files into repository by hand (you can hg add ignored files), purge probably may delete these files.
You can (rather easy) verify my idea after returning to good state of repo
Install|add hg-isignored extension (Bitbucket, will disapper soon due to BB-refugee from HG) and check ignorance state of versioned, but deleted by extension files (at least some of) - you'll see result and used pattern from .hgignore
Try (again) hg purge --print in order to get list of purged files. If lists (deleted and ignored versoned files) will have intersections, then you'll get answer on question "Why?"
I can't see any other reasons for such behavior of extension

Mercurial: how to revert changes purging files except those ignored (covered by '.hgignore')?

I made some exploratory changes to my code in a project under mercurial version control, so afterwards I wanted to discard all changes and go back to the last version in the remote repo.
hg pull
hg update -r default -C
hg --config "extensions.purge=" purge --all
What I didn't realize is that this will delete any untracked file, including those ignored. In particular eclipse directories like .settings. Obviously I don't want to delete those.
I know I can use patterns with the purge command, and most of the time I will want to use it only with changes under the source code directory, but if I had made changes not only under src, but also config, added a file at project directory level and whatnot, is there any way that purge could automatically pull files and directories from the .hgignore file to be excluded so I don't have to think all that directories and files in which I have untracked files?
Well... you explicitly used a flag which means "delete everything, even if ignored". From hg help purge:
--all purge ignored files too
So it should work, if you skip the '--all' parameter to purge.

Remove file from Mercurial repository without distribute a deletion

In my repository somebody committed files that should be unknown (or ignored, according the .hgignore file).
How can I tell to Mercurial to no longer track those files but leave the files as unknown (or ignored) on remote working copies? (With remote working copies I mean working copies of the other users of the repository.)
More details: Specifically those files are .classpath and .project generated by Eclipse IDE when the project was imported as Maven/Gradle project. They have been added to the repository and committed. I want to do not track changes of that files but I don't want to ask everybody to re-import the project into Eclipse again. Renaming .classpath and .project to .classpath.template and .project.template does not resolve my issue.
That is tricky, as the file will be stored as deleted in the changelog when you tell hg to forget it - and on update it will be deleted in the working dirs of everyone who pulls and updates to a rev later than the one where those files have been removed from tracking.
If you can get by with everyone using hg revert -rTRACKED FILENAME where TRACKED is the changeset where the files are (still) tracked, it is not really nice but probably the easiest solution.
You might want to add all files you do not want to be ever tracked to add to your .hgignore so that these won't be added by hg addremove accidentially.

Is it possible to update a mercurial repository to -1?

I want to "clear" my working directory for the moment (less space requirements for SSD and drive backups)
Specifically, I want to know if I can update to revision -1 (so that mercurial clears everything that is not itself).
Can this be done using a mercurial command? (I'll write a script if I have too, but it's advantageous to share a command with others rather than writing scripts that do the "right" thing)
If you run hg update null, it should remove everything except the .hg directory and any files not tracked by the repository.
If there were untracked files you can remove them as well using hg purge. Purge is an extension but it is distributed together with mecurial so you just have to enable it.
If you have uncommitted changes and don't care about preserving them, hg update -C null will take care of getting rid of them; all you will have left after this are the .hg directory and untracked files.

How do I remove all Java class files from my entire project history in Mercurial?

When I started my Mercurial project I forgot to exclude everything under my target/classes directory, such as:
target/classes/com/mypackage/MyClass.class
Now these binary files are causing conflicts when I do a hg update.
Is there a single command that would allow me to delete all of these files from the entire project history?
Or, if not, is there a command that would allow me to remove them one file at a time?
If you just want to remove files from last revision, remove files from disk and use hg addremove or hg remove --after target/classes/com/mypackage/*.class to inform Mercurial about your deletion.
If you want to permanently remove all class files from you entire history use hg convert and --filemap option to rewrite your repository and get rid of files from all revisions. However this solution alters revision ids. In multi user environment it may cause some problems because it creates a new repository effectively.
If you delete the files in question then do hg addremove then the files will be removed from the repository. However they will still be in the history though, but is that really a problem?
Use hg remove --after target/classes/com/mypackage/*.class. (--after will avoid deleting the on-disk files).