Grzenio
Grzenio

Reputation: 36689

Rollback of the last command in Mercurial

I just ran:

hg add .*

which matched all ../something files and which was something I certainly did't want! What is the easiest way to undo this command?

Upvotes: 1

Views: 1479

Answers (3)

alexis
alexis

Reputation: 50220

If you've got a lot of uncommitted adds that you don't want to have to do over, you can use a mercurial fileset that only picks out pending adds in subdirectories of the parent directory (use this in the same directory where the erroneous command was issued):

hg forget "set:../** and added()"

Mercurial doesn't remember what path you used to refer to a file, so this will forget all files (under the parent directory) that were just added; but if you were deep in a large repository, it'll limit the scope of what you discard.

Your question is similar to this recent question, but here we have an extra condition on the mistakenly added filenames.

Upvotes: 2

Martin Geisler
Martin Geisler

Reputation: 73808

There is not built-in way to undo a hg add command.

The underlying problem is that hg add is manipulating the so-called "dirstate" (short for "working directory state". This is where pending changes such as files scheduled for commit is stored — and this storage is unversioned.

There is an extension, though, that can help you: hg-multiundo will make backups of all files touched by Mercurial, including the dirstate. This means that you can use it to undo things like hg add or even hg revert --no-backup.

Upvotes: 1

Grzenio
Grzenio

Reputation: 36689

Not exactly what I was after, but made my life easier:

hg forget "set:added()"

this unmarks all the files that were added in the working repository. Obviously I also unmarked all the files that were added in preceding commands, so as I said this is not exactly what I was after...

Upvotes: 3

Related Questions