git在提交时报错error invalid path cannot add to the index的解决办法

Posted 但老师

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了git在提交时报错error invalid path cannot add to the index的解决办法相关的知识,希望对你有一定的参考价值。

背景

在写完打码,提交git的时候,报错如下

error: invalid path 'static/plugins/magic/' 
error: static/plugins/magic/: 
cannot add to the index - missing --add option? 
fatal: Unable to process path static/plugins/magic/

这种情况已经出现过至少两次了,记录一下解决方案吧


原因

因为我总是从Github上拉一些比较好用但是没有CDN的插件,上次是bootstrap fileinput,这次是magic,保存在static/plugins里面.就算是git clone下来的文件,仍然是一个仓库属性


解决方法

因为仓库里面再有仓库,所以会报这个error,删掉就好了.
大部分时候这个仓库属性是隐藏的,你需要删除掉的是这个仓库的.git文件夹

Mac方案

找到子项目文件夹,比如我这次的子项目文件夹是static/plugins/magic,按下command+shift+.

你就能在文件夹下看到隐藏文件.git,长下面这样

跟其他文件夹比,它看起来像半透明的,表示是一个隐藏文件夹
删掉就好了,然后push就可以成功


Windows方案

Win10下在这里显示隐藏文件夹

一样的,显示出来长这样,删掉就好了


- 完 -

以上是关于git在提交时报错error invalid path cannot add to the index的解决办法的主要内容,如果未能解决你的问题,请参考以下文章