Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hg remove directory from repo?

Tags:

mercurial

I'd like to remove a directory and all the files in it from a repo.

I have removed all the files with hg remove, but how do I remove the directory itself?

Will it just automatically vanish once I commit all the removed files?

like image 606
AP257 Avatar asked Oct 12 '10 17:10

AP257


People also ask

How to remove files from hg?

' hg forget ' is just shorthand for ' hg remove -Af '. From the ' hg remove ' help: ...and -Af can be used to remove files from the next revision without deleting them from the working directory. Bottom line: ' remove ' deletes the file from your working copy on disk (unless you uses -Af ) and ' forget ' doesn't.

How do you Untrack a file in Heartgold?

If you see the help for hg rm --help : hg remove [OPTION]... FILE... Schedule the indicated files for removal from the current branch. This command schedules the files to be removed at the next commit.


2 Answers

Yes. Because mercurial doesn't track directories at all, only files, it only creates directories that have files in them, and if someone hg updates to a revision any directories that become empty are automatically removed. So if you do:

hg remove directory/*
hg commit -m 'removed all files in directory'
hg update -r 0   # updates to a different revision
hg update tip    # jump back to the tip

That last update would remove the directory. For everyone else it's even easier. When they hg update to your new changes their directory will just vanish (provided they have no uncommitted file in it).

like image 83
Ry4an Brase Avatar answered Sep 22 '22 01:09

Ry4an Brase


hg remove dir

If you end up with empty directories and you want to get rid of them, an easy way is the purge extension. (add purge= under the [extensions] group in your .hrgc file to unlock).

You can then use

hg purge

to clean up the empty dirs... You must be careful with the purge command as it removes everything that is untracked in your repos. I strongly suggest you run a

hg purge -p

beforehand to see what the command will do ( -p will print a "test run" without doing anything.) Never forget the --help option! ;)

edit: I prefer using purge to hg update in succession as updating triggers rebuilds in my IDE if it is open (and it's a good bet it is when I do that). hg purge will probably be smoother. And you can use --all to include ignored files too (must be careful though).

like image 43
Eric-Karl Avatar answered Sep 25 '22 01:09

Eric-Karl