我从这篇文章中读到了解释为了使git跟踪文件夹,必须至少有一个空文件:
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.
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.
If you really need a directory to exist in checkouts you should
create a file in it.
Run Code Online (Sandbox Code Playgroud)
我遇到了一些问题,因为git没有跟踪空文件夹,我列举了一些:
问题1:
我apache/log
在我的一个git存储库中有一个目录.
当我把它推到服务器并运行网站时,它没有工作.它在我的本地系统中运行良好.经过大量的研究,我发现git push
没有推空文件夹/log
.服务检查文件夹日志以创建日志文件.由于文件夹log
不存在,因此无法自动创建文件夹并放置这些文件.这就是错误的原因.
问题2:
我有很多branch
.我的特定分支中只有一个说frontend
有文件夹caps
.
有时,目录中的一个文件夹my_git_repo/caps/html/home/
将为空.
分支master
没有文件夹caps
如果我使它git checkout master
将有空文件夹,即caps/html/home/tmp
所以我想手动删除文件夹caps
有时会造成混乱.
通常我通过README
在文件夹中放置一个空文件()来解决这些问题.
.git/config
或其他东西吗?任何帮助将被appriciated.:))
有一个非常空的文件夹,答案是否定的.由于Git在技术上如何处理数据,这是不可能的.
但是,如果你可以接受一些妥协:只需创建一些文件,比如.gitignore或你希望看到的目录中的任何内容,你就完成了.自述文件可以是一个解决方案,但我个人不会使用该名称,因为这会让人们认为这些文件中的内容存在混淆.
请参阅如何将空目录添加到Git存储库?对于一个非常相似的问题.
就我个人而言,我通常通过dir.info
在每个目录中调用一个文件来解决这个问题,其中有一些文本说明该目录的用途。
但是,如果您需要在结账后创建特定的空目录,并且这些目录可能特定于特定分支,我建议按订单制作git post-checkout 挂钩- 您可以在空的顶级目录中有一个列表需要和不需要的目录,用大约 5 行 python 就可以根据需要创建它们并删除不需要的目录。
我可能会做类似在第一个字符中包含-
或 之类的+
事情,具体取决于应删除或添加哪个字符。
类似的东西(添加了错误处理):
import os
dirlist = open("Dirlist.Name", "rt")
for line in dirlist:
flag = line[0]
name = line[1:].strip()
if flag == '+':
os.makedirs(name)
elif flag == '-':
os.removedirs(name)
else:
print "Ignored:", line
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
16521 次 |
最近记录: |