What are the differences between .gitignore and .gitkeep?
What are the differences between .gitignore and .gitkeep?
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
.
回答1
.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.
回答2
.gitignore
is a text file comprising a list of files in your directory that git will ignore or not add/update in the repository.
.gitkeep
Since Git removes or doesn't add empty directories to a repository, .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 repository.
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.
作者:Chuck Lu GitHub |
README
file in the otherwise empty subdirectory that contains a bit of information about what that subdirectory is going to be used for? It seems confusing to have a file called.gitkeep
that is not actually part of git. – tamouse Jul 14 '12 at 21:45