I read from this post which explains that to make git to track a folder there must atleast an empty file:
Currently the design of the Git index (staging area) only permits files
to be listed and nobody competent enough to make the change to allow
empty directories has cared enough about this situation to remedy it.
Directories are added automatically when adding files inside them.
That is, directories never have to be added to the repository,
and are not tracked on their own. You can say "git add <dir>" and it
will add the files in there.
If you really need a directory to exist in checkouts you should
create a file in it.
I have faced some problems because git not tracking empty folders, i am list a few:
Problem1:
I have a apache/log
directory in one of my git repository.
when I pushed it to server and run the website it didn't worked. Where it worked fine in my localsystem. after a lot of research i found out that git push
did n't pushed the empty folder /log
. the serve checked folder log to create logfiles. since folder log
did not exist, it is not possible to automatically create a folder and put these files. That is why the error.
Problem2:
I have lots of branch
. Only one of my particular branch say frontend
have folder caps
.
Sometime one of a folder in the directory my_git_repo/caps/html/home/
will be empty.
branch master
doesn't have folder caps
if i make git checkout master
it will have empty folder ie caps/html/home/tmp
so i want to manually delete the folder caps
sometimes it will create confusion.
usually i solve these problems by putting an empty file(README
) in the folder.
.git/config
or something?Any help will be appriciated.:))
Since Git won't track empty directories, you have to trick it into doing so by adding a file in the directory to Git's index. Usually, people store a file called . gitkeep in a directory that they wish to track, but where the directory should stay empty for the time being.
It ignores all directories. In Git, directories exist only implicitly, through their contents. Empty directories have no contents, therefore they don't exist.
Create an empty . gitignore file inside the empty folder that you would like to commit. Git will only track Files and the changes in them. So folders are tracked as part of the file changes in them.
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.
gitkeep feature. The . gitkeep feature is not a part of Git, but it is a trick we use to add empty directories to a Git repository. Generally, Git doesn't add empty directories and sometimes we may need to add them to a Git repository.
A GITKEEP file is an empty file that Git users create so that a Git repository preserves an otherwise empty project directory. By convention, empty directories that contain no files are not committed to Git repositories.
With a really empty folder, the answer is no. It's not possible because of how Git technically handles data.
BUT, if you're OK to accept some compromise: just create some file, like .gitignore or whatever inside the directory you want be seen, and you're done. README file can be a solution, but I would personnally not use that name because that would create confusion with people thinking there's content inside those files.
See How can I add an empty directory to a Git repository? for a very similar question.
Personally I usually solve this by having a file called dir.info
in every directory that has some text stating what the directory is there for.
However, if you need to create specific, empty, directories after a checkout with those directories possibly being specific to specific branches I would suggest git post-checkout hooks are made to order - you can have a list in your top level directory of the empty directories that are needed and not needed and with about 5 lines of python you can create them if required and delete those that are not.
I would probably do something like having -
or +
in the first char depending on which should be removed or added.
Something like, (with the error handling added):
import os
dirlist = open("Dirlist.Name", "rt")
for line in dirlist:
flag = line[0]
name = line[1:].strip()
if flag == '+':
os.makedirs(name)
elif flag == '-':
os.removedirs(name)
else:
print "Ignored:", line
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With