可以让git跟踪空文件夹吗? [英] Is it possible to make git to track empty folders?
问题描述
我从这篇帖子中读到,其中解释说要制作git跟踪一个文件夹必须至少有一个空文件:
目前Git索引(暂存区域)的设计只允许文件
被列出并且没有人能够做出改变以允许
空目录已经足够关心这种情况来补救它。
在添加文件时会自动添加目录。
也就是说,永远不必将目录添加到存储库
,并且不会自行跟踪。你可以说git add< dir>它
将在那里添加文件。
如果您确实需要在结帐时存在目录,您应该在
中创建一个文件。
我遇到了一些问题,因为git没有跟踪空文件夹,我列举了一些:
Problem1 :
我有一个 apache / log
目录在我的一个git仓库中。
当我将它推送到服务器并运行网站时,它不起作用。它在我的本地系统中工作得很好。经过大量研究,我发现 git push
没有推送空文件夹 / log
。服务检查文件夹日志以创建日志文件。由于文件夹 log
不存在,因此无法自动创建文件夹并放入这些文件。这就是为什么错误。
问题2 :
我有很多分支
。我的特定分支中只有一个说 caps
。
目录 my_git_repo / caps / html / home /
中的某个文件夹将为空。
branch master
没有文件夹 caps
如果我使用 git checkout master
它将会有空文件夹,例如 caps / html / home / tmp
so我想手动删除文件夹 caps
有时会造成混淆。
通常我会解决这些问题通过在文件夹中放置一个空文件( README
)。 所以我想让git来跟踪所有空文件夹。是否可以通过编辑 .git / config
或其他东西?
任何帮助都将被appriciated。:))
我个人通常通过一个名为 dir.info
在每个目录中都有一些文字说明目录是在那里。
然而,如果您需要在结帐后创建特定的空目录,具体到特定分支我建议 git post-checkout hooks 定制 - 你可以在你的顶级目录中有一个需要和不需要的空目录的列表,并且可以根据需要创建大约5行python,并删除那些不需要的。
我可能会在第一个字符取决于 +
应该被删除或添加。
类似于(添加了错误处理):
import os
dirlist = open(Dirlist.Name,rt)
for dirlist line:
flag = line [0]
name = line [1 :]。strip()
if flag =='+':
os.makedirs(name)
elif flag ==' - ':
os.removedirs(name)
else:
printIgnored:,line
I read from this post which explains that to make git to track a folder there must atleast an empty file:
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.
I have faced some problems because git not tracking empty folders, i am list a few:
Problem1:
I have a apache/log
directory in one of my git repository.
when I pushed it to server and run the website it didn't worked. Where it worked fine in my localsystem. after a lot of research i found out that git push
did n't pushed the empty folder /log
. the serve checked folder log to create logfiles. since folder log
did not exist, it is not possible to automatically create a folder and put these files. That is why the error.
Problem2:
I have lots of branch
. Only one of my particular branch say frontend
have folder caps
.
Sometime one of a folder in the directory my_git_repo/caps/html/home/
will be empty.
branch master
doesn't have folder caps
if i make git checkout master
it will have empty folder ie caps/html/home/tmp
so i want to manually delete the folder caps
sometimes it will create confusion.
usually i solve these problems by putting an empty file(README
) in the folder.
So I would like to make git to track all empty folders. is it possible by editing .git/config
or something?
Any help will be appriciated.:))
Personally I usually solve this by having a file called dir.info
in every directory that has some text stating what the directory is there for.
However, if you need to create specific, empty, directories after a checkout with those directories possibly being specific to specific branches I would suggest git post-checkout hooks are made to order - you can have a list in your top level directory of the empty directories that are needed and not needed and with about 5 lines of python you can create them if required and delete those that are not.
I would probably do something like having -
or +
in the first char depending on which should be removed or added.
Something like, (with the error handling added):
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
这篇关于可以让git跟踪空文件夹吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!