.gitignore和.gitkeep有什么区别?

本文翻译自:What are the differences between .gitignore and .gitkeep?

What are the differences between .gitignore and .gitkeep ? .gitignore.gitkeep什么.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 . 我似乎无法在.gitkeep上找到太多文档。


#1楼

参考:https://stackoom.com/question/UKp3/gitignore和-gitkeep有什么区别


#2楼

.gitkeep is just a placeholder. .gitkeep只是一个占位符。 A dummy file, so git will not forget about the directory, since git tracks only files. 一个虚拟文件,所以git不会忘记该目录,因为git只跟踪文件。


If you want an empty dir 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.) ('#'表示评论。)


#3楼

.gitkeep isn't documented, because it's not a feature of Git. .gitkeep没有记录,因为它不是Git的一个功能。

Git cannot add a completely empty directory . Git 无法添加一个完全空的目录 People who want to track empty directories in Git have created the convention of putting files called .gitkeep in these directories. 想要在Git中跟踪空目录的人已经创建了将这些名为.gitkeep文件放在这些目录中的约定。 The file could be called anything; 该文件可以被称为任何东西; Git assigns no special significance to this name. 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文件添加到空目录中以跟踪它们,但有些人认为这令人困惑,因为目标是保留空目录,而不是忽略它们; .gitignore is also used to list files that should be ignored by Git when looking for untracked files. .gitignore还用于列出Git在查找未跟踪文件时应忽略的文件。


#4楼

.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 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. 由于git删除或不添加空目录到repo .gitkeep是一种黑客(我不认为它被正式命名为git的一部分)在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. 只需touch /path/to/emptydirectory/.gitkeep即可添加文件,git现在可以在存储库中维护此目录。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值