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

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

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

30条回答
  •  不知归路
    2020-11-21 05:05

    You can't. See the Git FAQ.

    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

    " and it will add files in there.

    If you really need a directory to exist in checkouts you should create a file in it. .gitignore works well for this purpose; you can leave it empty, or fill in the names of files you expect to show up in the directory.

提交回复
热议问题