2012-07-22 2 views
11

Git tracks files, not directoriescannot currently add empty directories (standard trick은 빈 디렉토리를 추가하지 않고 그 안에있는 파일은 FAQ을 참조하십시오.)Git : repo에 빈 디렉토리가 있습니다. 어떻게됩니까?

그럼에도 불구하고 git repo에는 빈 디렉토리가있을 수 있습니다. 그래서 빈 디렉토리가있는 저장소를 repo 나 checkout으로 복제하면 어떻게됩니까? 작업 트리에서 생성 되었습니까?

답변

13

빈 디렉토리가있는 테스트 저장소를 설정하려면 다음 스크립트 (임시 디렉토리에서 실행)를 사용할 수 있습니다.

그러나 체크 아웃 할 때 빈 디렉토리는 무시됩니다. 여기에서도 Git은 디렉토리가 아니라 파일에서만 작동합니다.

Github 및 tig 빈 디렉터리 표시, gitk.

#!/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 
+1

사실이 트리는 저장소에 빈 트리를 추가합니다. 그러나 repo를 복제해도 작업 트리에 빈 디렉토리가 생성되지는 않습니다. – manu

관련 문제