You simply do the following:
mkdir images && touch images/.hgkeep
hg add images/.hgkeep
hg commit -m"Add the images folder as an empty folder"
Note the following as a consideration when you do this:
In your case you might be uploading images in your development environment, so I would also recommend adding the following to your .hgignore
file so you don't accidentally commit images you did not intend to commit:
^(images)\/(?!\.hgkeep)
The rule will ignore everything on images/**
except the .hgkeep
file you need to add an "empty" folder to version control. The reason why this rule is important, is that any files in that folder (ie. images/test-image.png
will look like a new non-versioned file in your hg status
if you don't ignore that pattern.
2I'm thinking naming it
.hgempty
might give a better clue as to what it's for – User – 2012-10-09T20:40:27.3908Yes or
.hgkeep
– Natim – 2012-10-10T07:28:05.0432Might as well go for verbose: .hgkeepifempty :) – Daniel Sokolowski – 2013-02-25T19:40:59.140
1Yes, that is indeed the correct solution: Mercurial is only keeping track of files, not directories. Another solution is to create the empty directories when you deploy your software. – Martin Geisler – 2009-12-21T23:23:33.797