无法将文件添加到Git存储库 [英] Not able to add files to Git repository

查看:357
本文介绍了无法将文件添加到Git存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试将所有文​​件添加到gitRepo时,它说:

When I am trying to add all files to gitRepo, it says:

$ git add .
error: 'ConnectorApp/' does not have a commit checked out
fatal: adding files failed

当我尝试删除空文件夹时,它说:

When I am trying to delete the empty folder, it says:

$ git rm ConnectorApp/
fatal: pathspec 'ConnectorApp/' did not match any files

还有其他解决方法可以清除此空文件夹,以将文件添加到gitRepo中?

Is there any other solution to clear this empty folder to add files to my gitRepo?

推荐答案

这不是一个空文件夹.这是一个子模块.

It's not an empty folder. It is a submodule.

空文件夹将是无关紧要的,因为Git仅存储文件,而不存储文件夹.文件的路径名可能类似于dir/file.ext.那不是包含file.ext的文件夹dir,而是一个名为dir/file.ext的文件.如果您的操作系统坚持使用 storing 这样的文件,例如名为dir的文件夹,其中包含名为file.ext的文件,那么当您需要使用它时,就可以了:Git将创建一个新文件.清空dir文件夹,并在必要时将名为file.ext的文件写入其中,例如在git checkout期间.但是Git仅存储了文件dir/file.ext.它尚未存储dir.

An empty folder would be irrelevant, because Git stores only files, not folders. A file's path name may be something like dir/file.ext. That's not a folder dir containing file.ext, but rather, just a file whose name is dir/file.ext. If your OS insists on storing such a file as a folder named dir containing a file named file.ext when you need to work on/with it, well, that's OK: Git will create a new empty dir folder and write into it a file named file.ext when necessary, during git checkout for instance. But Git has simply stored the file dir/file.ext. It has not stored dir.

但是在这种情况下,如果您更仔细地查看ConnectorApp/,包括查找通常隐藏的文件和目录/文件夹,您将看到存在ConnectorApp/.git.换句话说,ConnectorApp/本身就是它自己的Git存储库.一个Git存储库不能包含另一个Git存储库 1 ,因此,这里的Git存储库将第二个Git存储库记录为Git内部调用的 gitlink .

But in this case, if you look more closely at ConnectorApp/, including looking for normally-hidden files and directories/folders, you will see that there is a ConnectorApp/.git. In other words, ConnectorApp/ itself is its own Git repository. A Git repository cannot contain another Git repository,1 so instead, your Git repository here will record that second Git repository as what Git calls, internally, a gitlink.

gitlink背后的机制是,您的Git可以在您自己的机器上调用第二个子Git,以进入子存储库(Git称为子模块)并询问它:此存储库使用哪个提交?答案(如果有答案)将是原始提交哈希ID.

The mechanism behind a gitlink is that your Git can invoke a second sub-Git on your own machine, to enter the sub-repository—which Git calls a submodule—and ask it: Which commit is this repository using? The answer, if there is an answer, will be a raw commit hash ID.

外部存储库(Git称为 superproject )然后在每次提交中记录此原始哈希ID.运行git add ConnectorAppgit add ConnectorApp/ 2 会告诉您的超级项目Git输入子模块足够长的时间,以找出正确的哈希ID并将其存储/更新为gitlink条目.

The outer repository—which Git calls the superproject—then records, in each commit, this raw hash ID. Running git add ConnectorApp or git add ConnectorApp/2 tells your superproject Git to enter the submodule just long enough to find out the right hash ID and store/update it, as a gitlink entry.

错误消息告诉您,现在,子模块-其他Git-没有签出任何提交.因此,超级项目Git调用子模块Git并询问它您已签出哪个提交?,子模块Git说离开这里____,我没有任何东西!

The error message tells you that right now, the submodule—the other Git—does not have any commit checked out. So the superproject Git invokes the submodule Git and asks it which commit do you have checked out? and the submodule Git says get the ____ out of here, I don't have any!

要解决此问题,您有几种选择:

To fix the problem, you have several options:

  1. 不使用子模块.完全不要尝试添加ConnectorApp/.让您的超级项目是一个没有子模块的Git,并在超级项目的.gitignore中列出ConnectorApp/,这样它就不会尝试添加它.

  1. Don't use submodules. Don't try to add ConnectorApp/ at all. Have your superproject be a Git without a submodule, and list ConnectorApp/ in .gitignore in the superproject so that it doesn't try to add it.

仅当超级项目尚未已将ConnectorApp列为子模块时,此选项才有效.

This option only works if the superproject doesn't already list ConnectorApp as a submodule.

自己输入子模块,然后选择一个提交.那就是:

Enter the submodule yourself, and pick out a commit. That is:

cd ConnectorApp/
git checkout <something>
cd ..                      # return to superproject

您在 something 中填写的内容确定了当超级项目Git询问子模块Git 您已经签出了哪个提交哈希ID时,超级项目Git将看到的提交哈希ID. ?

这是您的超级项目提交可以记录要在子模块中使用的正确提交的方式.

This is how your superproject commit can record the correct commit to be used in the submodule.

如果您的超级项目Git有一个已记录的正确提交,则可以让超级项目Git告诉子模块Git签出记录的提交:

If your superproject Git has an existing recorded correct commit, you can have the superproject Git tell the submodule Git to check out the recorded commit:

git submodule update --checkout

(实际上,默认为--checkout,因此您通常可以省略它,但是有些配置项可以更改此设置).

(actually --checkout is the default, so you can typically omit it, but there are configuration items that can change this).

请注意,这适用于超级项目中列出的每个子模块.如果只有一个子模块,那就可以了.

Note that this applies to every submodule listed in the superproject. If there is only the one submodule, that's OK.

(请注意,您可能创建了不正确的子模块,其中超级项目的gitlink 没有,而其余信息是必需的.这里可能不是这种情况,但有时确实会发生这种情况.已经发生,请在StackOverflow上搜索有关此问题的答案.)

(Note that you can have improperly created submodules, where the superproject has a gitlink without the rest of the information required. This is probably not the case here, but it does happen sometimes. If it has happened, search StackOverflow for answers about that.)

1 没有技术理由,一个存储库不能包含另一个批发库,但是出于管理上的原因不这样做,因此Git被编程为不这样做

1There's no technical reason that one repository could not contain another one wholesale, but there are administrative reasons not to do that, so Git is programmed not to do that.

2 在糟糕的过去,git add ConnectorApp/会继续并将子模块中的所有文件添加到超级项目中.现在,此行为已修复,这使得子模块比以前更容易使用.但是,如果您有旧的Git,请当心:不要让斜线出现在其中!在这里,从Git 1.5或1.6天开始,我还有烧伤疤痕.

2In the bad old days, git add ConnectorApp/ would go ahead and add all the files from the submodule to the superproject. This behavior is fixed now, which makes submodules much more workable than they used to be. If you have an old Git, though, be careful: don't let that trailing slash in there! I still have some burn scars from Git 1.5 or 1.6 days here.

这篇关于无法将文件添加到Git存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆