git 提交空目录

2024-03-25 05:52
文章标签 提交 git 空目录

本文主要是介绍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/

这篇关于git 提交空目录的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/844030

相关文章

作业提交过程之HDFSMapReduce

作业提交全过程详解 (1)作业提交 第1步:Client调用job.waitForCompletion方法,向整个集群提交MapReduce作业。 第2步:Client向RM申请一个作业id。 第3步:RM给Client返回该job资源的提交路径和作业id。 第4步:Client提交jar包、切片信息和配置文件到指定的资源提交路径。 第5步:Client提交完资源后,向RM申请运行MrAp

git使用的说明总结

Git使用说明 下载安装(下载地址) macOS: Git - Downloading macOS Windows: Git - Downloading Windows Linux/Unix: Git (git-scm.com) 创建新仓库 本地创建新仓库:创建新文件夹,进入文件夹目录,执行指令 git init ,用以创建新的git 克隆仓库 执行指令用以创建一个本地仓库的

HTML提交表单给python

python 代码 from flask import Flask, request, render_template, redirect, url_forapp = Flask(__name__)@app.route('/')def form():# 渲染表单页面return render_template('./index.html')@app.route('/submit_form',

Python3 BeautifulSoup爬虫 POJ自动提交

POJ 提交代码采用Base64加密方式 import http.cookiejarimport loggingimport urllib.parseimport urllib.requestimport base64from bs4 import BeautifulSoupfrom submitcode import SubmitCodeclass SubmitPoj():de

git ssh key相关

step1、进入.ssh文件夹   (windows下 下载git客户端)   cd ~/.ssh(windows mkdir ~/.ssh) step2、配置name和email git config --global user.name "你的名称"git config --global user.email "你的邮箱" step3、生成key ssh-keygen

查看提交历史 —— Git 学习笔记 11

查看提交历史 查看提交历史 不带任何选项的git log-p选项--stat 选项--pretty=oneline选项--pretty=format选项git log常用选项列表参考资料 在提交了若干更新,又或者克隆了某个项目之后,你也许想回顾下提交历史。 完成这个任务最简单而又有效的 工具是 git log 命令。 接下来的例子会用一个用于演示的 simplegit

记录每次更新到仓库 —— Git 学习笔记 10

记录每次更新到仓库 文章目录 文件的状态三个区域检查当前文件状态跟踪新文件取消跟踪(un-tracking)文件重新跟踪(re-tracking)文件暂存已修改文件忽略某些文件查看已暂存和未暂存的修改提交更新跳过暂存区删除文件移动文件参考资料 咱们接着很多天以前的 取得Git仓库 这篇文章继续说。 文件的状态 不管是通过哪种方法,现在我们已经有了一个仓库,并从这个仓

忽略某些文件 —— Git 学习笔记 05

忽略某些文件 忽略某些文件 通过.gitignore文件其他规则源如何选择规则源参考资料 对于某些文件,我们不希望把它们纳入 Git 的管理,也不希望它们总出现在未跟踪文件列表。通常它们都是些自动生成的文件,比如日志文件、编译过程中创建的临时文件等。 通过.gitignore文件 假设我们要忽略 lib.a 文件,那我们可以在 lib.a 所在目录下创建一个名为 .gi

取得 Git 仓库 —— Git 学习笔记 04

取得 Git 仓库 —— Git 学习笔记 04 我认为, Git 的学习分为两大块:一是工作区、索引、本地版本库之间的交互;二是本地版本库和远程版本库之间的交互。第一块是基础,第二块是难点。 下面,我们就围绕着第一部分内容来学习,先不考虑远程仓库,只考虑本地仓库。 怎样取得项目的 Git 仓库? 有两种取得 Git 项目仓库的方法。第一种是在本地创建一个新的仓库,第二种是把其他地方的某个

Git 的特点—— Git 学习笔记 02

文章目录 Git 简史Git 的特点直接记录快照,而非差异比较近乎所有操作都是本地执行保证完整性一般只添加数据 参考资料 Git 简史 众所周知,Linux 内核开源项目有着为数众多的参与者。这么多人在世界各地为 Linux 编写代码,那Linux 的代码是如何管理的呢?事实是在 2002 年以前,世界各地的开发者把源代码通过 diff 的方式发给 Linus,然后由 Linus