在未填充的子模块中

我对 github 还很陌生,我正在努力寻找解决当前问题的方法。我将一步一步地完成我的过程:

首先,我创建了一个名为 [project name]的新文件夹 接下来,我使用了以下命令:

    cd [project name]
git clone [remote project from github url]

到目前为止,我已经创建了一个文件夹,并克隆了一个项目,我的小组正在 github 中工作。

接下来,我进入那个文件夹并创建了一个有棱角的项目

    ng new [angulartest]

这将把我的角度测试的所有组件创建到相同的文件夹中,这个文件夹是 github 的克隆文件夹。

最后,我用

    git add [angulartest]
git commit
git push

它只推送文件夹 [angulartest],但不推送其内容(即使文件夹中有内容)。当我试图从它的内容,我仍然只得到一个空文件夹作为回报。

当我尝试进入该文件夹并添加内容的每个元素时,使用以下步骤:

    cd [angulartest]
git add e2e, src, nodemodules, etc
git commit
git push

它给出了以下错误(即使我试图单独添加每个元素) :

fatal: in unpopulated submodule [angulartest]

我想知道是我的 git 语法有问题,还是棱角项目有问题,或者是我试图克隆项目的方式有问题。这样,在寻找解决方案时,我就知道自己想往哪个方向走了。

66166 次浏览

It seems like, you may have removed the .git folder. In that case you can try

 git rm --cached angulartest -f

Here's what I did

  1. Make a copy of the 'submodule' directory somewhere outside of the repository (e.g. your desktop)
  2. Delete the submodule directory from your repo
  3. Commit the repo
  4. Go into the copy you made of your submodule directory, delete .gitignore file and .git directory
  5. Copy the submodule directory back into your repo and commit

This meant I lost the commit history of the submodule but at least it fixed the issue of my files in the submodule not going to git!

git rm --cached . -rf

Stealing from anlijudavid's comment which was the actual answer for me on macOS with zsh. Adding -r based on Richard Collette's comment to this answer.

The root cause of this error in my case was that I have a subdirectory with its own .git folder inside. When I issued the git add --all command, I got this same error

Here's how I resolved the issue

  1. Remove all .git folder inside the sub directory causing the error
  2. cd to the main directory
  3. git rm --cached sub_directory_name -f
  4. git add --all to add the subdirectory and contents, recursively
  5. git status to verify that the items are added

I almost got a headache with this error but thanks for the previous answers, a combination of those worked for me.

If we cloned from third party repository we got this " fatal: in unpopulated submodule 'submodule name' " error.

This error fix for me using

git rm --cached <submodule name> -f

Also you can remove .git folder manually then you can try to git add

I got the same error when I had a subdirectory in my local repo, had deleted the .git to solve different issue, and then tried to add an updated html file to my repo. I went to github and uploaded the file using their GUI. Now I can see that everyhting matches and git status shows no issues.