在Git存储库中运行`git add .git`会发生什么?

And*_*rio 24 git git-add

虽然它似乎什么都不做,但没有给出任何警告或错误信息.有任何想法吗?

man*_*lds 21

来自Git的评论来源:

/*
 * 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.
 */
Run Code Online (Sandbox Code Playgroud)

实验,看看发生了什么,如果我创建一个文件.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)
Run Code Online (Sandbox Code Playgroud)

所以是的,.git- 无论是目录还是文件,都被git忽略了.

如果我做以下的事情:

git --git-dir="c:/test" --work-tree="c:/test" add c:/test
Run Code Online (Sandbox Code Playgroud)

所有元文件都被添加.

所以,就我所见,只有.git被忽略的不是git元数据文件夹(你设置的--git-dir).


ctc*_*rry 18

简短回答:没什么.

答案很长:

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$ 
Run Code Online (Sandbox Code Playgroud)