Git 跟踪文件,而不是目录,我们当前不能add清空目录(标准技巧不会添加空目录,而是添加文件,请参阅常见问题解答).
然而,git repo可能包含一个空目录.那么我会克隆一个repo或签出一个包含空目录的分支会发生什么?它是在工作树中创建的吗?
tiw*_*iwo 16
要使用空目录设置测试存储库,可以使用以下脚本(在临时directoy中运行它).
但是,在签出时,将忽略空目录.在这里,Git只适用于文件,而不是目录,即使后者存在.
#!/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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21568 次 |
| 最近记录: |