Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to forget all removed files with Mercurial

Tags:

mercurial

I am new to Mercurial and after a cleanup of the image folder in my project, I have a ton of files showing with ! in the 'hg status'. I can type a 'hg forget ' for each, but there must be an easier way.

So how can I tell mercurial to forget about all the removed (status = !) files in a folder?

like image 248
ADB Avatar asked Mar 24 '10 16:03

ADB


People also ask

How do I delete a file from Mercurial?

Once you decide that a file no longer belongs in your repository, use the hg remove command. This deletes the file, and tells Mercurial to stop tracking it (which will occur at the next commit). A removed file is represented in the output of hg status with a “ R ”.

How do I remove untracked files from Mercurial?

Add the Mercurial Extension called purge. It is distributed by Mercurial. It is not enabled by default, maybe to avoid accidentally removing files that you forgot to add.

How do I revert my hg add?

hg revert -r . ^ path-to-file will revert the commit from the commit-set. then commit and submit (if using jelly fish) and you'll see the files removed from the changeset.

What does exclamation mark mean in Mercurial?

As @Riley pointed out, it means they're missing. An alternative method of removing them from the repository is to use hg remove --after <filename> .


4 Answers

If you're also okay with adding any files that exist and aren't ignored then:

hg addremove

would a popular way to do that.

like image 198
Ry4an Brase Avatar answered Oct 05 '22 18:10

Ry4an Brase


With fileset (Mercurial 1.9):

hg forget "set:deleted()"

In general, on Linux or Mac:

hg status -dn | while read file ; do hg forget "$file" ; done

Or, if your shell allows it, if there are not too many files, and if the filenames do not contain spaces or special characters, then:

hg forget $(hg st -dn)

I

like image 28
peak Avatar answered Oct 05 '22 16:10

peak


You can try:

hg forget -I '*'

in order to include all files in your forget command.

like image 34
VonC Avatar answered Oct 05 '22 18:10

VonC


By using the -d flag for status, which displays missing files:

for file in $(hg status -d | cut -d " " -f 2); do echo hg forget $file; done

Run this in the root of your repo, and if you're happy with the results, remove the echo

This has the bonus over the accepted answer of not doing any additional work, e.g. adding a bunch of untracked files.

like image 32
eqzx Avatar answered Oct 05 '22 18:10

eqzx