Ancestors

Toot

Written by Curtis "Ovid" Poe (he/him) on 2024-12-28 at 09:07

Sometimes you want to just have an empty directory in git, but not commit any files in it.

touch data/.gitkeep

And add this to your .gitignore:

data/*

!data/.gitkeep

Then commit. Now you have an "empty" directory.

[#]git #programming

=> More informations about this toot | More toots from ovid@fosstodon.org

Descendants

Written by Mohit Sindhwani on 2024-12-28 at 09:11

@ovid

Ya, I think Rails creates directories with a .keep in them for exactly this reason

=> More informations about this toot | More toots from onghu@ruby.social

Written by arialdo on 2024-12-28 at 09:22

@ovid when does an empty directory is needed? I cannot think of a single case where an empty directory is needed but at run time. And I consider any run time artifact responsibility of the build script, not the versioning system.

=> More informations about this toot | More toots from arialdo@mastodon.online

Written by Curtis "Ovid" Poe (he/him) on 2024-12-28 at 09:31

@arialdo In my case, I want an uploads directory to always be there, but not commit those files. When I run my tests, I don't want to always recreate that, nor duplicate build system logic. It also makes the directory very visible to anyone else checking out the project, so they can see structure just by browsing.

You also might want "empty" directories if you're doing heavy refactoring and don't want to lose structure in the interim.

=> More informations about this toot | More toots from ovid@fosstodon.org

Written by arialdo on 2024-12-28 at 12:35

@ovid wouldn’t you consider that directory as part of the run time, as opposed to the compile time?

=> More informations about this toot | More toots from arialdo@mastodon.online

Written by Veit Schiele on 2024-12-28 at 11:45

@ovid IMHO, a better way is to create a .gitignore file with the following content in an empty directory:

[#] ignore everything except .gitignore

!.gitignore

This technique avoids several disadvantages:

• Both .gitignore and log/.gitkeep must be edited.

• When renaming the directory, it is easy to forget to change the .gitignore file as well.

• .gitkeep is a completely normal file for Git; however, the name suggests that the file would be treated specially by Git.

=> More informations about this toot | More toots from veit@mastodon.social

Proxy Information
Original URL
gemini://mastogem.picasoft.net/thread/113729658789934257
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
269.506618 milliseconds
Gemini-to-HTML Time
1.417093 milliseconds

This content has been proxied by September (3851b).