Mercurial - How to remove a file from version control?
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:
- Copy the config file somewhere outside of the repository.
- Run
hg rm path/to/config/file
- Add the config file path to your
.hgignore
. - Commit the repository.
- Move the config file back to where you had it.
- 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.
- Run
hg forget path/to/config/file
- Edit your
.hgignore
and add the path to the config file. -
hg ci
to save your changes. - 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.
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, 2020Comments
-
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?