How to do Mercurial's 'hg remove' for all missing files?

90,535

Solution 1

This will add all new files that are not ignored, and remove all locally missing files

hg addremove

Either of these will remove all locally missing files(They are the same command)

hg remove --after
hg remove -A

Solution 2

If you intend to do addremove and commit, it can be joined with '-A' option as shown here:

hg commit -A -m 'Commit with addremove'

Solution 3

The original question asked how to remove (i.e. forget) files that show up as "!" when using hg st. A direct approach which has the advantage of transparency is to use hg st with the -n option:

hg -v forget $(hg st -nd)

(Of course the files will only be forgotten at the next commit.)

The flags are well-documented elsewhere (e.g. by the hg command itself), but in brief:

  • -n means "filename only"
  • -d means "select files that have been deleted"

Solution 4

If you want to addremove and commit, but are not ready to commit the rest of your changes, I think you still have to enumerate them:

$ hg st
M modified-file
A added-file
R removed-file-1
R removed-file-2

$ hg commit -m"remove removed-file-1 and removed-file-2" removed-file-*
abort: removed-file-*: No such file or directory

$ hg commit -m"remove removed-file-1 and removed-file-2" removed-file-1 removed-file-2
committed changeset 185:628800a7af84
Share:
90,535

Related videos on Youtube

Marcus Leon
Author by

Marcus Leon

Director Clearing Technology, Intercontinental Exchange. Develop the clearing systems that power ICE/NYSE's derivatives markets.

Updated on March 22, 2020

Comments

  • Marcus Leon
    Marcus Leon over 4 years

    I use this to remove a file from the repo:

    hg remove <full file path> 
    

    What command can you use to do an hg remove on all files that have been deleted locally?

    By deleted locally, I mean those showing up with an ! when you do hg status.

    For adds, you can just do hg add to add all new files (those prefixed with ?).

  • jk.
    jk. over 14 years
    there is also hg forget which is eqivalent to hg rm -Af
  • Lester Peabody
    Lester Peabody almost 13 years
    the jk for a username is menacing, i feel like evertime i read one of your comments or posts you are saying "just kidding" at the end :( that being said, this helped, cheers!
  • Richard B
    Richard B over 10 years
    one word of warning... don't freak out when it dumps a whole bunch of crap to the screen... (like I did)
  • Cullub
    Cullub over 8 years
    Wow! Thanks! That helped a lot! Wow! +1 :) hg rm -A
  • Cullub
    Cullub over 8 years
    Can you explain each of those flags?
  • Yaakov Bressler
    Yaakov Bressler almost 4 years
    Phew! This saved me a whole bunch of time, thank you!