2011-07-27 48 views
19

虽然它什么都不做,它没有给出任何警告或错误信息。有任何想法吗?当你在Git仓库中运行`git add .git`时会发生什么?

+7

其实是一个相关的问题;我承认我只是做了。我这样做是因为我想添加'.gitignore',但是在'.git'处停止了制表符,所以无意中我做到了。而且我(像你)担心的是“我摧毁了什么?”。 – Jarl

回答

19

评论:

/* 
* Read a directory tree. We currently ignore anything but 
* directories, regular files and symlinks. That's because git 
* doesn't handle them at all yet. Maybe that will change some 
* day. 
* 
* Also, we ignore the name ".git" (even if it is not a directory). 
* That likely will not change. 
*/ 

实验,看看发生了什么,如果我创建一个文件.git,并尝试添加它: (在Windows上我不能创建文件.git已经有一个.git文件夹我也可以在子目录中的其他地方创建.git但是想要尝试--git-dir--work-tree我以前没有用过。毕竟我在做实验。这也让我证明我可以添加git的元数据文件夹,如下图所示)

git --git-dir="c:/test" init 
touch blah 
git --git-dir="c:/test" --work-tree="." add . 
git --git-dir="c:/test" --work-tree="." status (shows blah added) 
touch .git 
git --git-dir="c:/test" --work-tree="." add .git (no output as usual) 
git --git-dir="c:/test" --work-tree="." status (only blah shown) 

所以呀,.git - 无论是目录或文件,由混帐忽略。

如果我这样做如下:

git --git-dir="c:/test" --work-tree="c:/test" add c:/test 

所有的元文件被添加。

所以再次,只有.git被忽略,而不是git元数据文件夹(您通过--git-dir设置),据我所知。

+0

您在哪个文件/修订版本中找到了此评论? –

+0

没关系,找到它 - https://github.com/git/git/blob/fe9122a35213827348c521a16ffd0cf2652c4ac5/dir.c#L1277 –

+0

你是什么意思的“git元数据目录”?不是你用'--git-dir'设置你的工作目录的目录吗? – HelloGoodbye

16

简答:没什么。

龙答:从SVN源

laptop:Projects ctcherry$ mkdir test 
laptop:Projects ctcherry$ cd test 
laptop:test ctcherry$ git init . 
Initialized empty Git repository in /Users/ctcherry/Projects/test/.git/ 
laptop:test ctcherry$ git add .git 
laptop:test ctcherry$ git status 
# On branch master 
# 
# Initial commit 
# 
nothing to commit (create/copy files and use "git add" to track) 
laptop:test ctcherry$