Mercurial - How to remove a file from version control?

30,188

Solution 1

Right click on the file -> TortoiseHG -> Forget Files. Click Forget. Commit and Sync.

Edit: You'll also want to add the path to your .hgignore to keep it from getting added again. You can right click on the file in the HG Commit dialog and choose to ignore it.

Solution 2

Here's the manual way of doing it through the command line:

  1. Copy the config file somewhere outside of the repository.
  2. Run hg rm path/to/config/file
  3. Add the config file path to your .hgignore.
  4. Commit the repository.
  5. Move the config file back to where you had it.
  6. Do an hg stat on your repository to double check you did everything right. (It shouldn't show up in the list of modified/added files).

Edit:

hg forget is the best way to do this.

  1. Run hg forget path/to/config/file
  2. Edit your .hgignore and add the path to the config file.
  3. hg ci to save your changes.
  4. Run hg stat to ensure everything worked according to plan.

See nates answer for how to do it TortoiseHG.

Solution 3

hg remove or hg remove -f? I think hg forget also removes it from the branch.

In both cases, files are retained in your directory.

Share:
30,188
Greg
Author by

Greg

I'm an avid programmer, web developer and electronics enthusiast. Here's my gift to Python hackers. And you can see everything I'm up to here.

Updated on June 08, 2020

Comments

  • Greg
    Greg about 4 years

    So I accidentally included a config file (different for each machine) into our mercurial repositories.

    How can I get Mercurial to not include it in version control? I don't want to delete the file since I still want it. And I don't want to cause the file to get deleted on other developer's working directories either.

    And how do I do this in TortoiseHG?