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

后端 未结 30 2616
离开以前
离开以前 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:10

    Let's say you need an empty directory named tmp :

    $ mkdir tmp
    $ touch tmp/.gitignore
    $ git add tmp
    $ echo '*' > tmp/.gitignore
    $ git commit -m 'Empty directory' tmp
    

    In other words, you need to add the .gitignore file to the index before you can tell Git to ignore it (and everything else in the empty directory).

提交回复
热议问题