Niklas Rosencrantz
Niklas Rosencrantz

Reputation: 26655

Removing binaries from an hg repository

Is it possible with Mercurial to remove all files with a certaain extension? I did an addremove and then all my binary .pyc were versioned and now I get this stopper when I do versioning:

tool kdiff3 can't handle binary
tool docdiff can't handle binary
 no tool found to merge bnano-www/wtforms/widgets.pyc
keep (l)ocal or take (o)ther? o
19 files updated, 67 files merged, 0 files removed, 0 files unresolved

C:\Users\developer\bnano\bnano-www>

I don't really know what it means except I can press o for other and go on with my work. Now I'd like to clean my repository and optimal would be to be able to do an addremove without binaries getting added but I think it is not possible.

Can you give some recommendation what to do in this case?

Thanks

Upvotes: 6

Views: 1698

Answers (3)

Cody Piersall
Cody Piersall

Reputation: 8547

To remove all binary files from a repository, you can use Mercurial filesets:

hg remove "set:binary()"

And as the other posters mentioned, it's a great idea to add unwanted extensions in the .hgignore file.

Upvotes: 3

krtek
krtek

Reputation: 26597

HgIgnore

First of all, you can add some rules to the .hgignore file to tell Mercurial that you want to ignore some files. Then, hg addremove won't add them automatically and they won't appear in the output of the commands (ie hg status) as untracked.

Removing the files

To remove your files, you can use hg remove myfile, for example, if all your pyc files are in the same directory, you can do hg remove *.pyc and then commit the change.

If your files are scattered in various repository, something like hg remove -I *.pyc **/* should remove all .pyc files in all directories.

Exclusion patterns

FYI, will it's better to add unwanted files in the .hgignore file, you can also tell addremove to ignore some files by doing hg addremove -X *.pyc. This will add/remove every files except those having the pyc extension.

You can find help about a specific mercurial command using help. For example, hg help addremove. In general everything is neatly explained !

Tutorial

To explore various Mercurial concepts in more depth, I recommand this excellent tutorial : http://hginit.com

Upvotes: 7

jkerian
jkerian

Reputation: 17016

You should be able to remove them like any other file hg remove *.pyc. You probably want to add .pyc to the .hgignore file to keep them from coming back when you use addremove.

In general though, you should be using hg add to selectively add files in the future, given that as the project develops, what files it contains should stabilize relatively quickly.

Upvotes: 1

Related Questions