Physical AI News (Japan)

Physical AI, robotics and compute — reported from Japan.

日本語
· Industry· 日本語で読む

Qiita Explains How to Track Empty Directories in Git and When to Use Each Method

A Qiita article outlines ways to include empty directories in Git commits. .gitkeep and .gitignore are used differently depending on whether files added later should be tracked. For compilation output directories, the article says the appropriate approach depends on the language and how directory names are handled.

What happened

An article explaining how to include empty directories in Git commits was published on Qiita. It covers how to choose between .gitkeep and .gitignore and precautions when tracking directories used for compilation output.

Why it matters

The choice between .gitkeep and .gitignore depends not only on whether an empty directory should be preserved, but also on whether files later added there should be tracked. In particular, for compilation output directories, users need to check that exclusion rules do not affect files they want to track, depending on the extension and directory-name conditions cited in the article.

Analysis

The article focuses less on the syntax for preserving an empty directory than on the difference in policy for handling files that may later appear there. Adding .gitkeep indicates an intention to track files users add, even if the directory is currently empty. By contrast, adding .gitignore indicates that files generated there, such as logs or caches, should not be tracked. The two are therefore not simply interchangeable options; they express the directory's purpose and how its contents should be handled in the repository. This distinction also matters when setting up directories for development work to be shared. The article's example of a directory for database migrations is intended for files users create, even if it initially contains none. By contrast, a location for logs or caches signals a policy of not tracking generated files. The article's point is that even when the goal is the same — preserving an empty directory — the appropriate method differs depending on the nature of the files that may later be added. The article's guidance on compilation output directories can be understood in terms of two conditions: whether files can be excluded by extension alone, and whether there is a commonly understood name for the output directory. It gives examples of specifying extensions for C++ and Java, while cautioning against simple extension-based exclusions or excluding a directory in TypeScript because .js is also used for other purposes and there is no generally accepted name for the output directory. This illustrates how broadly applied exclusion rules can also exclude files that should be tracked. The examples in the article do not, however, establish which method is always appropriate for any given project. The choice requires checking whether the output directory needs to be shared, what types of files it contains and the existing .gitignore settings. See the original article for specific examples and further details.

Sources

Translated from the Japanese original: /news/qiita-git-de-sora-direkutori-wo-atsukau-houhou-wo-kaisetsu-97d588. The Japanese version is authoritative if they differ.