bph
bph

Reputation: 11278

mercurial discard all added files prior to a commit

Just made the mistake of using addremove to try and remove some files that were deleted without using hg remove

Now have hundreds of files that are going to be added on the next commit

Is there anyway I can quickly remove all these added files without having to resort to a bash script or even worse hg removing or forgetting each file manually?

Upvotes: 3

Views: 147

Answers (2)

icabod
icabod

Reputation: 7084

If you want to just use internal hgcommands, you can do the following:

hg forget "set:added()"

Which will forget any file that's marked as "added" in the working directory. It makes use of the rather powerful filesets feature of Mercurial.

There are additional filters you can use when specifying files, which allows you to easily fix other mistakes. For example, easily re-add removed files but nothing else hg add "set:removed()". The functionality is similar to (tho' thankfully simpler than) mercurial revsets, and can be studied with:

hg help filesets

Upvotes: 7

krtek
krtek

Reputation: 26617

You do it quite easily on the command line using something along the lines of :

hg status --added --no-status | xargs hg forget

This should forget all files added since the last commit.

May I suggest to add the files you never want to add to a .hgignore file so this won't happen again ?

Upvotes: 3

Related Questions