Home » Questions » Computers [ Ask a new question ]

How to add an empty folder in a Mercurial project?

How to add an empty folder in a Mercurial project?

In my project, I am using Mercurial and a folder in when the user can upload file. But since the user will upload files, the folder is empty.

Asked by: Guest | Views: 216
Total answers/comments: 2
bert [Entry]

"Mercurial only keeps track of files, not directories.

One solution is to add a .empty file to your repository:

$ touch uploads/.empty
$ hg add uploads/.empty"
bert [Entry]

"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."