Applying hgignore file to already committed file Mercurial repo
Asked Answered
D

2

5

Trying to do something similar to here: Applying .gitignore to committed files

Where you apply the new hgignore file to the already committed files.

I have node_modules folder already committed with thousands of files and I'd like to remove it by using the new hgignore file.

I can't find anything online for it to work on a Mercurial repo, any ideas? Thanks!

Defamation answered 10/8, 2017 at 8:28 Comment(2)
.hgignore only ignores untracked files. It won't ignore already committed files. You have to hg remove the files and commit the change.Halvah
To add to what @MarkTolonen already said, note that Git and Mercurial behave the same here: files that are tracked/committed are not ignored, by definition. Only an untracked file can be ignored. Or, to put it another way, "ignored" is a quiet flavor of "untracked".Quartet
E
9
  1. Edit .hgignore to match files you want to ignore
  2. hg forget "set:hgignore()" and commit

See in action:

See also:

Espalier answered 13/8, 2017 at 0:26 Comment(1)
^This is still a life saviour to this day!Defamation
O
0

This is very easy once you get the steps. hgignore does not apply to the files already committed for tracking.

I use Tortoise Hg Workbench for UI.

In case build related binary files are checked in that need not be tracked, try this. When a rebuild is done, those files will again appear under files to commit. You can see this by selecting the green Commit button in the toolbar.

Select the files you want to ignore, then right click and select "Forget" (remember you have already committed the file earlier). This would mark the files as "R" for removal. Select the checkboxes next to the file and commit.

After commit, there would be a “?” mark next to those files and will appear in pink. Select those files and right click and select "Ignore". This would bring up the hgignore editor. Add to .hgignore from that editor.

Commit the .hgignore as well so that you have it safe.

In case you are using this for your personal work, why dont you try VSTS, its really cool, has both git and TFS as the backhaul! I moved all my personal work to VSTS.

Note: Sorry for not being able to upload screen shots, absolutely tight on schedule.. :(

Odont answered 8/3, 2018 at 13:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.