当您在 Git 存储库中运行“git add .git”时会发生什么?

发布于 2024-11-26 12:59:17 字数 39 浏览 1 评论 0原文

虽然它似乎什么也没做,但它没有给出警告或错误消息。有什么想法吗?

While it seemed to do nothing, it gave no warning or error message. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

十六岁半 2024-12-03 12:59:17

来自 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.
 */

实验看看如果我创建一个文件 .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 --git-dir="c:/test" --work-tree="c:/test" add c:/test

所有元文件都会被添加。

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

Comment from Git source:

/*
 * 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.
 */

Experiment to see what happend if I create a file .git and try to add it:
(on Windows I cannot create a file .git when there is already a .git folder. I also could have created a .git elsewhere in a sub directory, but wanted to try out --git-dir and --work-tree which I haven't used before. After all I am experimenting. This also allows me to show that I can add the git metadata folder as seen below)

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)

So yeah, .git - be it directory or file, is ignored by git.

And if I do something like below:

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

all the meta files get added.

So again, it is only .git that is ignored not the git metadata folder (that you set via --git-dir) as far as I can see.

哎呦我呸! 2024-12-03 12:59:17

简短的回答:没什么。

长答案:

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$ 

Short answer: Nothing.

Long answer:

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$ 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文