git .gitignore 和 .gitkeep 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7229885/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are the differences between .gitignore and .gitkeep?
提问by Matty
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?
.gitignore
和之间有什么区别.gitkeep
?它们是名称不同的同一个东西,还是它们都有不同的功能?
I don't seem to be able to find much documentation on .gitkeep
.
我似乎无法在.gitkeep
.
回答by Wooble
.gitkeep
isn't documented, because it's not a feature of Git.
.gitkeep
没有记录,因为它不是 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.
Git不能添加一个完全空的目录。想要在 Git 中跟踪空目录的人已经创建了将文件.gitkeep
放入这些目录中的约定。该文件可以被称为任何东西;Git 没有赋予此名称任何特殊意义。
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.
将.gitignore
文件添加到空目录以跟踪它们是一种相互竞争的约定,但有些人认为这令人困惑,因为目标是保留空目录,而不是忽略它们;.gitignore
还用于列出 Git 在查找未跟踪文件时应忽略的文件。
回答by sjas
.gitkeep
is just a placeholder. A dummy file, so Git will not forget about the directory, since Git tracks only files.
.gitkeep
只是一个占位符。一个虚拟文件,所以 Git 不会忘记目录,因为 Git 只跟踪文件。
If you want an empty directory and make sure it stays 'clean' for Git, create a .gitignore
containing the following lines within:
如果您想要一个空目录并确保它对 Git 保持“干净”,请创建一个.gitignore
包含以下行的目录:
# .gitignore sample
###################
# Ignore all files in this dir...
*
# ... except for this one.
!.gitignore
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:
如果您希望 Git 只能看到一种类型的文件,这里是一个如何过滤除 .gitignore 和所有.txt
文件之外的所有文件的示例:
# .gitignore to keep just .txt files
###################################
# Filter everything...
*
# ... except the .gitignore...
!.gitignore
# ... and all text files.
!*.txt
('#' indicates comments.)
('#' 表示注释。)
回答by Jim Munro
.gitignore
is a text file comprising a list of files in your directory that git will ignore or not add/update in the repository.
是一个文本文件,包含目录中的文件列表,git 将忽略或不在存储库中添加/更新。
.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.
由于 Git 删除或不向存储库添加空目录,因此 .gitkeep 是一种在存储库中保留空目录的黑客(我不认为它被正式命名为 Git 的一部分)。
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.
只需touch /path/to/emptydirectory/.gitkeep
添加文件,Git 现在就可以在存储库中维护这个目录。