Is it possible to make git to track empty folders?

This question already has an answer here:

  • How can I add an empty directory to a Git repository? 28 answers

  • 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
    

    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.

    链接地址: http://www.djcxy.com/p/7864.html

    上一篇: 上传一个空文件夹给github

    下一篇: 可以让git跟踪空文件夹吗?