git 怎么跟踪空目录

【问题描述】
git和 svn不同,仅仅跟踪文件的变动,不跟踪目录。所以,一个空目录,如果里面没有文件,即便 git add 这个目录,另外在别处 check out 的时候,是没有这个空目录的。

有时候,确实需要在代码仓库中保留某个空目录。比如测试时需要用到的空目录。下面来看看如何解决:

【解决方案】

Track Empty Directories with git
git 跟踪空文件夹

There are times when you’d like to track an empty directory within git but there’s a problem: git wont allow you to add a directory that doesn’t have a file in it. The easy solution is putting an empty stub file within the directory, and the industry standard for that stub file name is .gitkeep.

有时您想跟踪git中的空目录,但是有一个问题:git不允许您添加其中没有文件的目录。 一种简单的解决方案是在目录中放入一个空的存根文件,该存根文件名的行业标准是.gitkeep 。

You can quickly create the file and commit the “empty” directory from command line:

您可以快速创建文件并从命令行提交“空”目录:

touch my-empty-dir/.gitkeep
git add my-empty-dir/.gitkeep
git commit -m "Adding my empty directory"

注:my-empty-dir是指代空目录路径

The problem is simple, the solution is easy, but I wanted to highlight that .gitkeep is the industry standard.

问题很简单,解决方案很容易,但我想强调.gitkeep是行业标准。

翻译自:https://davidwalsh.name/git-empty-directory

上述方法注意:不要在项目的.gitignore中设置忽略.gitkeep文件,.gitkeep 是一个约定俗成的文件名并不会带有特殊规则

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

吾爱技术圈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值