How to stop tracking a file without deleting it on Mercurial

18,822

You can just use hg forget or maybe add the file to your .hgignore file

And to answer the last question about the R in my_file. If you see the help for hg rm --help:

hg remove [OPTION]... FILE...

aliases: rm

remove the specified files on the next commit

Schedule the indicated files for removal from the current branch.

This command schedules the files to be removed at the next commit. To undo
a remove before that, see "hg revert". To undo added files, see "hg
forget".

Returns 0 on success, 1 if any warnings encountered.

options:

-A --after record delete for missing files
-f --force remove (and delete) file even if added or modified
-I --include PATTERN [+] include names matching the given patterns
-X --exclude PATTERN [+] exclude names matching the given patterns

[+] marked option can be specified multiple times

use "hg -v help remove" to show more info

As you can see you are forcing the deletion of that file and that's why you can see the R (Removed)

Share:
18,822

Related videos on Youtube

Amelio Vazquez-Reina
Author by

Amelio Vazquez-Reina

I'm passionate about people, technology and research. Some of my favorite quotes: "Far better an approximate answer to the right question than an exact answer to the wrong question" -- J. Tukey, 1962. "Your title makes you a manager, your people make you a leader" -- Donna Dubinsky, quoted in "Trillion Dollar Coach", 2019.

Updated on August 02, 2022

Comments

  • Amelio Vazquez-Reina
    Amelio Vazquez-Reina almost 2 years

    I saw this thread which discusses a solution for git, and found this thread on the mailing list for Mercurial (the thread is four years old though)

    The solution proposed in the mailing list is to use hg rm -Af file (and they leave open the possibility of implementing this behavior as a new, more intuitive option). I'm wondering if that option exists now.

    Also, if I try the command above:

    > hg rm -Af my_file
    > hg st
    R my_file
    

    there is an R next to my_file, but the file my_file is technically on disk, and I have told Mercurial to stop tracking it, so why am I getting R next to it?

  • Amelio Vazquez-Reina
    Amelio Vazquez-Reina over 12 years
    Thanks I think the reason why I got confused is because hg forget myfile (which seems to be an alias for hg rm -Af myfile) marks the file so that hg stops tracking it after committing (which is why the Hg shows R next to file until I commit)
  • CodeLurker
    CodeLurker almost 6 years
    Not working for me. I do the forget, the remove, and the commit, and after that, every damn time I recompile my project, test.exe keeps showing up at the commit as modified.