在复制了一个已有项目到新项目目录后,发现有一个子目录中部分文件无法添加到 Git 管理中。这个子目录的特点是,曾经包含
.git
目录,后被我手动删除,然后这个目录部分文件无法添加到 Git 管理中(总之就是有文件无法被Git追踪),而且用 git status [–ignored] 也看不出端倪。
查看已被排除的文件
git status --ignored # ignored 参数会列出被Git忽略追踪的文件
并未发现该目录中未被追踪的文件。
submodule
一个子目录中如果包含 .git
目录,会被认作一个 git submodule,其无法被 git add 进当前项目。
需要
:
- 先删除子目录下的
.git
目录; - 然后
git rm --cached directory
; - 最后
git add
、git commit
、git push
此目录。
注:Git可以直接
add
、commit
、push
一个目录。
总结:
git rm --cached directory # 清除缓存
git add directory # 添加至暂存区
git commit -m "<message>" directory # 提交至本地库
git push # 推送至远程库
注:directory即是未被git追踪的目录。