stav
stav

Reputation: 199

git ignores empty folders

Currently my project structure looks like this:

and I want to add a "build" directory to it, so that people know where to build with cmake.

I want the build directory to be empty, so in my .gitignore I added:
build/*
so that it ignores everything in that directory.

The problem is that git also doesn't track the directory because its empty. So I tried adding a README.txt (containing "build cmake solutions here") to make it so that git would track it, (And I edited the .gitignore file, obviously) but, unfortunately, that seem to mess up cmake.

When I try to build on windows using the cmake gui and choose the build directory, it doesn't generate the visual studio solution, but when I remove the README.txt file from the folder, cmake works again.

I'm guessing it's because cmake doesn't allow any other files in the build directory.

So I cant have the README.txt file in the folder because it messes up cmake for some reason, but I also can't leave the directory empty because that will make git stop tracking it....

So what do I do?

Upvotes: 2

Views: 417

Answers (2)

utopia
utopia

Reputation: 1535

In the "project" directory, I have a .gitignore file containing:

!.gitignore
!/build/*

In the "project/build" directory, I have a .gitignore file containing:

# Ignore everything in this directory
*
# - except .gitignore and README files
!.gitignore
!README*

I even put in a "project/build/README.txt" file with "build cmake solutions here" as text.

Everything checks into git, including the "build" and .gitignore files.

Everything builds correctly with Visual Studio 2015 Win64 and Ninja generators with cmake-gui and cmake from command line.

Upvotes: 0

Rhys Johns
Rhys Johns

Reputation: 109

I mean it might sound odd, but why not just put that README.txt file you created at the top most folder in your project hierarchy. That way you can explain it to anyone who uses the project, and your not checking in empty folders into your VCS.

Upvotes: 0

Related Questions