Git:repo包含一个空目录 - 会发生什么? [英] Git: repo contains an empty directory - what happens?

查看:86
本文介绍了Git:repo包含一个空目录 - 会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Git 跟踪文件,而不是目录,我们目前无法添加空目录标准技巧< a>不添加一个空目录,而是添加一个文件,另请参阅常见问题)。

Git tracks files, not directories, and we cannot currently add empty directories (The standard trick does not add an empty directory, but instead a file within, see also the FAQ).

然而,git repo 可能包含一个空目录。那么,我会克隆一个repo还是检出一个包含一个空目录的分支?是否在工作树中创建?

Nevertheless, a git repo may contain an empty directory. So what happens I clone a repo or checkout a branch containing an empty directory? Is it created in the work tree?

推荐答案

要使用空目录设置测试库,可以使用以下脚本在临时directoy中运行它)。

To setup a test repository with an empty directory, you can use the following script (run it in a temporary directoy).

然而,检出时,将忽略空目录。在这里,Git只适用于文件,而不适用于目录,即使后者存在。

When checking out, however, the empty directory is ignored. Here too, Git only works with files, not directories, even if the latter are present.

Github和 tig 显示空目录, gitk 不。

Github and tig display empty directories, gitk does not.

#!/bin/bash
set -e

echo ---- initialize the repo...
#rm -rf .git
git init

echo ---- create an empty tree object...
empty_tree=$(git mktree < /dev/null)

echo ---- create a parent tree containing the empty subtree...
root_tree_ls=$(echo -e 040000 tree $empty_tree\\tvacuum)
root_tree=$(echo "$root_tree_ls" | git mktree)

echo ---- commit...
commit_msg="This commit contains an empty directory"
commit=$(git commit-tree $root_tree -m "$commit_msg")

echo ---- create a branch...
git branch master $commit

# output the ids:
echo ----------------------------------------------------
echo "empty tree:" $empty_tree
echo "root tree: " $root_tree
echo "commit:    " $commit

这篇关于Git:repo包含一个空目录 - 会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆