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

后端 未结 30 2627
离开以前
离开以前 2020-11-21 04:52

How can I add an empty directory (that contains no files) to a Git repository?

30条回答
  •  梦毁少年i
    2020-11-21 05:01

    Another way to make a directory stay (almost) empty (in the repository) is to create a .gitignore file inside that directory that contains these four lines:

    # Ignore everything in this directory
    *
    # Except this file
    !.gitignore
    

    Then you don't have to get the order right the way that you have to do in m104's solution.

    This also gives the benefit that files in that directory won't show up as "untracked" when you do a git status.

    Making @GreenAsJade's comment persistent:

    I think it's worth noting that this solution does precisely what the question asked for, but is not perhaps what many people looking at this question will have been looking for. This solution guarantees that the directory remains empty. It says "I truly never want files checked in here". As opposed to "I don't have any files to check in here, yet, but I need the directory here, files may be coming later".

提交回复
热议问题