当前位置: 首页 > news >正文

git 提交空目录

git 提交空目录

  • 1. git 无法感应空目录
  • 2. git 提交空目录
  • References

1. git 无法感应空目录

Git FAQ
https://archive.kernel.org/oldwiki/git.wiki.kernel.org/index.php/GitFaq.html

Currently the design of the Git index (staging area) only permits files to be listed, and nobody competent enough to make the change to allow empty directories has cared enough about this situation to remedy it.

目前 Git 索引 (暂存区) 的设计只允许列出文件。

Directories are added automatically when adding files inside them. That is, directories never have to be added to the repository, and are not tracked on their own. You can say git add <dir> and it will add the files in there.

在添加目录中的文件时,目录会被自动添加。目录永远不必添加到存储库中,也不会自行跟踪。git add <dir> 会添加目录中的文件。

If you really need a directory to exist in checkouts you should create a file in it. .gitignore works well for this purpose; you can leave it empty or fill in the names of files you do not expect to show up in the directory.

如果你真的需要一个目录存在,你应该在其中创建一个文件。.gitignore 可以很好地用于此目的,你可以将其留空或填写你不希望出现在目录中的文件名。

git 是用来索引文件的,它只关注文件,不关心目录。git 根据文件的内容去计算 hash 的,仅仅新增一个目录,git 是没办法处理的。

yongqiang@yongqiang:~/yongqiang_work/darknet$ git status
On branch master
Your branch is up to date with 'origin/master'.nothing to commit, working tree clean
yongqiang@yongqiang:~/yongqiang_work/darknet$
yongqiang@yongqiang:~/yongqiang_work/darknet$ mkdir yongqiang
yongqiang@yongqiang:~/yongqiang_work/darknet$
yongqiang@yongqiang:~/yongqiang_work/darknet$ git status
On branch master
Your branch is up to date with 'origin/master'.nothing to commit, working tree clean
yongqiang@yongqiang:~/yongqiang_work/darknet$

2. git 提交空目录

需要在目录下创建 .gitkeep.keep 文件,在项目的 .gitignore 中设置不忽略 .gitkeep
.gitkeep.keep 是一个约定俗成的文件名并不会带有特殊规则。

strong@foreverstrong:~/gogsgit_work/parking_system$ mkdir tmp
strong@foreverstrong:~/gogsgit_work/parking_system$ 
strong@foreverstrong:~/gogsgit_work/parking_system$ cd tmp/
strong@foreverstrong:~/gogsgit_work/parking_system/tmp$ ls
strong@foreverstrong:~/gogsgit_work/parking_system/tmp$ 
strong@foreverstrong:~/gogsgit_work/parking_system/tmp$ touch .gitkeep
strong@foreverstrong:~/gogsgit_work/parking_system/tmp$ 
strong@foreverstrong:~/gogsgit_work/parking_system/tmp$ ll
total 8
drwxrwxr-x 2 strong strong 4096 Jun 27 17:08 ./
drwxrwxr-x 8 strong strong 4096 Jun 27 17:07 ../
-rw-rw-r-- 1 strong strong    0 Jun 27 17:08 .gitkeep
strong@foreverstrong:~/gogsgit_work/parking_system/tmp$ cd ..
strong@foreverstrong:~/gogsgit_work/parking_system$ 
strong@foreverstrong:~/gogsgit_work/parking_system$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:(use "git add <file>..." to include in what will be committed)tmp/nothing added to commit but untracked files present (use "git add" to track)
strong@foreverstrong:~/gogsgit_work/parking_system$ 
strong@foreverstrong:~/gogsgit_work/parking_system$ git add .
strong@foreverstrong:~/gogsgit_work/parking_system$ 
strong@foreverstrong:~/gogsgit_work/parking_system$ git commit -m "add tmp"
strong@foreverstrong:~/gogsgit_work/parking_system$ git push

​​​
git 已经能感知到这个目录的存在了,其实是感应到里面那个 .gitkeep.keep 文件的存在。

References

[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/

http://www.lryc.cn/news/327063.html

相关文章:

  • 【优化方案】Java 将字符串中的星号替换为0-9中的数字,并返回所有可能的替换结果
  • C语言复习-链表
  • Redis面试题-缓存雪崩、缓存穿透、缓存击穿问题
  • 【Node.js】npx
  • hive授予指定用户特定权限及beeline使用
  • Vmware虚拟机无法用root直连说明
  • Visio中存在问题的解决方法
  • taro之Swiper的使用
  • 正大国际:金融行业发展趋势
  • vue中实现超出一行 展开和收起的功能
  • 记录一次使用cert-manager-颁发CA证书
  • 生成式AI的风险与挑战
  • 让IIS支持.NET Web Api PUT和DELETE请求
  • 运维小技能:IP多号段配置、重置Mac电脑密码、修改系统级别的文件
  • Docker的Ubuntu上的安装教程及相关命令
  • 一些常见的nacos问题和答案
  • 华为OD机22道试题
  • 什么是Prompt Tuning?
  • 正则表达式篇
  • CAST(columnA AS VARCHAR(255)) AS fieldA报错的问题
  • github加速神器!解决github巨慢的问题,并且能够加速下载!另外推荐GitKraken -- 超好用的 Git 可视化工具
  • Stable Diffusion XL之使用Stable Diffusion XL训练自己的AI绘画模型
  • 软件杯 深度学习 机器视觉 人脸识别系统 - opencv python
  • IDEA | 资源文件中文乱码问题解决
  • Linux系统使用Docker部署Portainer结合内网穿透实现远程管理容器和镜像
  • 【Git篇】复习git
  • [LitCTF 2023]程序和人有一个能跑就行了
  • 如何在群晖NAS搭建bitwarden密码管理软件并实现无公网IP远程访问
  • perl:获取同花顺数据--业绩快报,业绩公告
  • FPGA选型