How can I add an empty directory (that contains no files) to a Git repository?
相关问题
- How to access the camera from my Windows Phone 8 a
- Why does recursive submodule update from github fa
- Extended message for commit via Visual Studio Code
- Emacs shell: save commit message
- Can I organize Git submodules in a flat hierarchy?
相关文章
- 请教Git如何克隆本地库?
- GitHub:Enterprise post-receive hook
- Git Clone Fails: Server Certificate Verification F
- SSIS solution on GIT?
- Is there a version control system abstraction for
- ssh: Could not resolve hostname git: Name or servi
- Cannot commit changes with gitextensions
- git: retry if http request failed
The solution of Jamie Flournoy works great. Here is a bit enhanced version to keep the
.htaccess
:With this solution you are able to commit a empty folder, for example
/log
,/tmp
or/cache
and the folder will stay empty.Here is a hack, but it's funny that it works (Git 2.2.1). Similar to what @Teka suggested, but easier to remember:
git submodule add path_to_repo
).submodules
. Commit a change..submodules
file and commit the change.Now, you have a directory that gets created when commit is checked out. An interesting thing though is that if you look at the content of tree object of this file you'll get:
I wouldn't encourage to use it though since it may stop working in the future versions of Git. Which may leave your repository corrupted.
You can't. See the Git FAQ.
Let's say you need an empty directory named 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).
When you add a
.gitignore
file, if you are going to put any amount of content in it (that you want Git to ignore) you might want to add a single line with just an asterisk*
to make sure you don't add the ignored content accidentally.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.