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.

 

Wouldn't it be a better solution to put a 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

 

@tamouse many times, the path of the empty directory (e.g. names of the folders) is sufficient to express it's purpose (examples: templates/cache, upload/thumbs etc). In these cases putting a readme into each of these feels redundant. – Halil Özgür Jan 31 '13 at 8:33

 

回答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    
posted @   ChuckLu  阅读(45)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2020-07-13 Comparison Review: Microsoft SSDT vs Redgate SQL Source Control
2020-07-13 Azure DevOps Azure Repos Git How-to Guides Use SSH key authentication
2019-07-13 de4dot 反混淆
2019-07-13 GreyMagic
2019-07-13 HearthBuddy 第一次调试
2019-07-13 dnSpy
2018-07-13 How to check HTML version of any website
点击右上角即可分享
微信分享提示