What are the differences between .gitignore
and .gitkeep
? Are they the same thing with a different name, or do they both serve a different function? I don't seem to be able to find much documentation on .gitkeep
.
相关问题
- 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?
- Upload file > 25 MB on Github
相关文章
- 请教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
.gitkeep
isn’t documented, because it’s not a feature of Git.Git cannot add a completely empty directory. People who want to track empty directories in Git have created the convention of putting files called
.gitkeep
in these directories. The file could be called anything; Git assigns no special significance to this name.There is a competing convention of adding a
.gitignore
file to the empty directories to get them tracked, but some people see this as confusing since the goal is to keep the empty directories, not ignore them;.gitignore
is also used to list files that should be ignored by Git when looking for untracked files..gitkeep
is just a placeholder. A dummy file, so git will not forget about the directory, since git tracks only files.If you want an empty dir and make sure it stays 'clean' for git, create a
.gitignore
containing the following lines within:If you desire to have only one type of files being visible to git, here is an example how to filter everything out, except .gitignore and all
.txt
files:('#' indicates comments.)
is a text file comprising a list of files in your directory that git will ignore or not add/update in the repository.
Since git removes or doesn't add empty directories to a repo .gitkeep is sort of a hack (I don't think it's officially named as a part of git) to keep empty directories in the repo.
just do a
touch /path/to/emptydirectory/.gitkeep
to add the file and git will now be able to maintain this directory in the repository.