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

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

    As mentioned it's not possible to add empty directories, but here is a one liner that adds empty .gitignore files to all directories.

    ruby -e 'require "fileutils" ; Dir.glob(["target_directory","target_directory/**"]).each { |f| FileUtils.touch(File.join(f, ".gitignore")) if File.directory?(f) }'

    I have stuck this in a Rakefile for easy access.

提交回复
热议问题