Live data from Hacker News

Don't create .gitkeep files, use .gitignore instead (2023)

adamj.eu

91–100 of 101 posts

Re: Don't create .gitkeep files, use .gitignore instead (2023)

#91

Maybe the correct thing to do is to modify git so that it can track an otherwise-empty directory and then never have to worry about this problem again. Is there a reason why this is hard to integrate into git's existing model of the filesystem?

1. Nobody sees this as a big issue.

2. As-is situation is good enough.

3. I guarantee that you will have colleagues that will accidentally add empty dirs. (I definitely have seen when they accidentally add built artefacts; dirs would be lesser issue as they would not increase repo size by much, but still)

4. Actually only first two reasons matter, but for nitpickers there would be also a bit dishonest but formally correct pointing to some doc saying that it is file or content tracker (and formally directory is not a content)

Re: Don't create .gitkeep files, use .gitignore instead (2023)

#92
post #66

Earlier quoted context omitted.

Yeah... I don't think you were wrong. Having 100 tiny gitignores makes finding out why something is excluded annoying. Our policy is one root level gitgnore and gitkeeps where required. Some devs will just open the first gitignore they see and throw stuff into it. No thank you.

I like to make a .local folder at the top of the project, which contains a .gitignore that ignores everything. Then I can effortlessly stash my development notes there without affecting the project .gitignore or messing around within the .git directory.

Why not put '.local' in your toplevel gitignore, and not commit an empty .local folder up to the forge?

Re: Don't create .gitkeep files, use .gitignore instead (2023)

#94
post #52

The author makes a very common mistake of not reading the very first line of the documentation for .gitignore. A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected; see the NOTES below for details. You should never be putting "!.gitignore" in .gitignore. Just do `echo "*" > .gitignore; git add -f .gitignore`. Once a file is tracked any changes…

I think I'd prefer to have all ignores and un-ignores explicitly in the file and not have some of them defined implicitly because a file was added to tracking at some point.

But ignore files are only for untracked files anyway. Maybe you want them to specify what can be in the repo and what not, but this is not how Git works.

Re: Don't create .gitkeep files, use .gitignore instead (2023)

#95
post #50

Earlier quoted context omitted.

qemu: mkdir build; cd build; ../configure, some projects are like that

Why can’t the configure script do this?

Because the standard for configure scripts says that the current directory at invocation is the build directory and the location of the configure script is the source directory. You are expected to be able to have multiple build directories if you want them. If you have written your configure script correctly, than in-tree builds (srcdir == builddir) also work, but most people don't want that anyway.

Re: Don't create .gitkeep files, use .gitignore instead (2023)

#96

Maybe the correct thing to do is to modify git so that it can track an otherwise-empty directory and then never have to worry about this problem again. Is there a reason why this is hard to integrate into git's existing model of the filesystem?

Git only tracks files not directories, so yeah you would need to change a lot. It is also unclear what the semantics should be. What is with a directory that is tracked as r--, but then files get added?

Re: Don't create .gitkeep files, use .gitignore instead (2023)

#97
post #92
post #66

Earlier quoted context omitted.

I like to make a .local folder at the top of the project, which contains a .gitignore that ignores everything. Then I can effortlessly stash my development notes there without affecting the project .gitignore or messing around within the .git directory.

Why not put '.local' in your toplevel gitignore, and not commit an empty .local folder up to the forge?

Upstream never sees an empty .local folder because, as established, Git doesn't keep empty folders. This way, .local isn't mentioned in the top-level .gitignore. It's just that tiny bit cleaner.

Re: Don't create .gitkeep files, use .gitignore instead (2023)

#98
post #66

Earlier quoted context omitted.

Yeah... I don't think you were wrong. Having 100 tiny gitignores makes finding out why something is excluded annoying. Our policy is one root level gitgnore and gitkeeps where required. Some devs will just open the first gitignore they see and throw stuff into it. No thank you.

I like to make a .local folder at the top of the project, which contains a .gitignore that ignores everything. Then I can effortlessly stash my development notes there without affecting the project .gitignore or messing around within the .git directory.

You can create a global gitignore in your home directory. I have ‘.’ ignored there, so if I ever create a directory with that name I know it’s contents won’t go into source control. That way I don’t have to edit the repositories gitignore with me-specific stuff.

Re: Don't create .gitkeep files, use .gitignore instead (2023)

#99
post #98
post #66

Earlier quoted context omitted.

I like to make a .local folder at the top of the project, which contains a .gitignore that ignores everything. Then I can effortlessly stash my development notes there without affecting the project .gitignore or messing around within the .git directory.

You can create a global gitignore in your home directory. I have ‘. ’ ignored there, so if I ever create a directory with that name I know it’s contents won’t go into source control. That way I don’t have to edit the repositories gitignore with me-specific stuff.

You wouldn't have to edit the actual repositories gitignore anyways. Every checkout of a repo comes with a .git/info/exclude file, which acts like a local additional gitignore file.

Re: Don't create .gitkeep files, use .gitignore instead (2023)

#100

Earlier quoted context omitted.

I play around with ComfyUI on my computer to make silly images. To manually install it, you must clone the repo. Then you have to download models into the right place. Where's the right place? Well, there's an empty directory called models. They go in there. IMO that's an effective use of gitkeep.

It's not. echo >repo/models/README.md "this is the directory you place models in" Is infinitely better.

    echo >repo/models/README.md "this is the directory in which you place models"
x

Pedant

Post reply on HN