logoalt Hacker News

beej71today at 4:04 AM1 replyview on HN

What am I missing about this use case? It seems like you should just create `build/.gitignore` with `*` in it and `add -f` it and be done.

I'd use `.gitkeep` (or an empty `.gitignore`) if I needed to commit an otherwise-empty hierarchy. But if I'm going to have a `.gitignore` in there anyway, it's not empty.

> The directory is now “tracked” with a single, standard file that will work even after renames.

Does `.gitkeep` not work after renames? Or `.gitignore`?

So I am missing something. :)


Replies

KPGv2today at 4:46 AM

That's a hack. What you should do is a .gitignore with * and then a whitelist of paths like src/**/*.

If you rely on `add -f` you will forget to commit something important.

For example, for a tree sitter grammar I developed a couple years ago, here is my .gitignore:

```

# Ignore everything

*

# Top-level whitelist

CHANGELOG.md

# Allow git to see inside subdirectories

!*/

# Whitelist the grammar and tests

!/grammar/*.js

!/test/corpus/*.txt

# Whitelist any grammar and tests in subdirectories

!/grammar/**/*.js

!/test/corpus/**/*.txt

```*

show 1 reply