23

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?

ADB
  • 2,319
  • 1
  • 24
  • 35
  • Duplicate: http://stackoverflow.com/questions/2412239/how-to-do-mercurials-hg-remove-for-all-missing-files – Cullub Jan 18 '16 at 20:24
  • Not exactly a duplicate, though solving either one requires listing files that don't show up in `ls`. That question asks how to mark deleted files as hg removed. This one is how to *un*mark all the hg removed files. – Joshua Goldberg Jul 20 '16 at 16:51

5 Answers5

27

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.

Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169
  • 2
    True, adding untracked files and marking missing files as removed in one shorthand command. +1 – VonC Mar 24 '10 at 18:56
  • This works for recursive folder traversal too, where-as the forget -I has to be performed in the directory of the files to be removed. – Nick Josevski Oct 12 '11 at 05:12
10

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

peak
  • 105,803
  • 17
  • 152
  • 177
3

You can try:

hg forget -I '*'

in order to include all files in your forget command.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

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.

eqzx
  • 5,323
  • 4
  • 37
  • 54
0

more shorter instead of

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

this

hg status -d | cut -d " " -f 2 | xargs echo hg forget # test case
hg status -d | cut -d " " -f 2 | xargs hg forget # real work
Serhii Kuzmychov
  • 1,186
  • 8
  • 10