问题描述

  • 在提交hexo博客项目时,./themes/indigo是一个子项目,在不知道
    的情况下提交至远程仓库,结果indigo文件夹的内容并没有上传,在本
    地删除.git文件夹,然后继续执行git add -A命令,结果提示分支是干
    净的,没有要提交的东西。

探索过程

  • 使用关键词 项目中有文件夹无法add进去 ,按照文章执行如下命令
    git add -f ./themes/indigo/*,报错如下:
1
fatal: Pathspec './themes/indigo/_config.yml' is in submodule 'themes/indigo'
  • 使用报错信息中的 fatal: Pathspec is in submodule 作为关键词继续搜索发现另一篇文章里的内容:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
简述下出现的情况:
1.之前从github上,clone了一个clockpicker的插件,然后,直接将整个版本库,复制到了项目中
2.发现版本库中,并未记录到该目录!查看 '.gitignore' 等,也并未找到忽略该目录
3.进入clockpicker目录下,发现有.git, .gitignore,因为原本就是完整的一个git仓库,猜想和这个有关,然后删除的只剩下 dist, src。然后 git status 查看,发现扔未记录
4.强制 git add dist 目录,出现错误:
fatal: Pathspec 'dist/' is in submodule 'public/components/clockpicker'
5.google搜索:
https://stackoverflow.com/questions/24472596/git-fatal-pathspec-is-in-submodule


原因解释:
This works if you purposefully removed the .git directory because you wanted to add directory to your main git project. In my specific case, I had git cloned an extension and ran git add . without thinking too much. Git decided to create a submodule, which I didn't like. So I removed directory/.git and ran into Git: fatal: Pathspec is in submodule. I couldn't find out how to remove the submodule stuff. Fixed with the two lines above.


在我的主项目中,我clone一个git扩展,并运行了git add,并没有想太多。在这种情况下,git会创建一个子模块(也就是报错中的submodule),然后,就同我上面的第3步一样,将.git等等都删除了。然后运行git add 报错!
-----------------
不懂,反正大概意思了解就行,尽量不要在我们的项目中,再引入其他git仓库,我们自己都觉得不太对劲...


解决方案:
git rm --cached clockpicker
git add clockpicker才能够
  • 分析文章发现,应该是在首次提交时没有删除子项目中的.git文件夹,结果
    在上传时git自动把项目转化为子模块submodule,导致无法add。解决问题的关键
    在于删除根项目子模块记录,执行以下命令成功提交:
1
2
3
4
git rm --cached ./themes/indigo
git add -A
git commit -m 'indigo inject'
git push

附:

1.git各种add的区别

1
2
3
git add . #将目录下所有新增和修改存至缓存区,但不包括删除
git add -u #将目录下所有修改和删除存至缓存区,但不包扣新增
git add -A #缓存所有改动

2.markdown

markdown基本语法

markdown使用手册

3.git命令

常用 Git 命令清单

更多精彩->请进入我的博客

参考

git 添加文件和目录的时候,老是不能包括在git里。

git 出现 fatal: Pathspec ‘assets/‘ is in submodule ‘public/components/clockpicker’,解决方法