I have a CakePHP project under Mercurial version control. Right now all the files in the
app/tmp directory are being versioned, which are always changing.
I do not want to version control these files.
I know I can stop by running
hg forget app/tmp/*
But this will also forget the file structure. Which I want to keep.
Now I know that Mercurial doesn't version directories, just files, but the CakePHP folks were also smart enough to put an empty file called
empty in every empty directory (I am guessing for this reason).
So what I want to do is tell Mercurial to forget every file under
app/tmp except files whos name is exactly empty.
What would the command be for this?
Well, if nothing else works, you can always just ask Mercurial to forget everything, and then revert
empty before committing:
Here's how I reproduced it, first create initial repo:
hg commit -m "initial" -A
Then add some files we later want to get rid of:
echo a >app\tmp\test1.txt
echo a >app\tmp\test2.txt
hg commit -m "adding" -A
Then forget the files we don't want:
hg forget app\tmp\*
hg status <-- will show all 3 files
hg revert app\tmp\empty
hg status <-- now empty is gone
hg commit -m "ignored" -A
Note that all
.hgignore does is to prevent Mercurial from discovering new files during
commit -A, if you have explicitly tracked files that match your ignore filter, Mercurial will still track changes to those files.
In other words, even though I asked Mercurial to ignore
app/tmp above, the file
empty inside will not be ignored, or removed, since I have explicitly asked Mercurial to track it.
At least theoretically (I don't have time to try it right now), pattern matching should work with the
hg forget command. So, you could do something like
hg forget -X empty while in the directory (
-X means "exclude").
You may want to consider using .hgignore, of course.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!Donate Us With