Git无法add已经修改过的文件

文件修改后,通过git add来暂存之前修改的内容

$ git add -A .

然后再次执行git status时,却提示no changes added

$ git status
On branch coding-pages
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
          modified:   themes/next (new commits)
no changes added to commit (use "git add" and/or "git commit -a")

遇到这种问题只好google一番:
如果你想执行git add -A,那在每个子模块中,你应该:

$ git submodule foreach --recursive git add -A .

然后,你要在每个子模块中创建一个commit

$ git submodule foreach --recursive "git commit -m 'Committing in a submodule'"

这样你就可以git add,git commit了。

在 stackoverflow 上说并不推荐这种做法,应该每一个子模块被看成是一个独立的库来处理。
使用git add -A . 命令是直接添加了git库,而不是添加git子库。这个问题通常出现在你想添加其他git库的文件到你自己的库并直接使用git add命令去暂存它,如果换成git submodule add <REPOSITORY-URL>则可避免此情况发生。如果说你很想将其用submodules的方式储存的话,我强烈建议你在将其移除出你的库,并提交删除,重新用git submodule add的方式添加。

附上链接:git add -A is not adding all modified files in directories

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容