git仓库包含子仓库时,add报错的解决办法

在父仓库内部克隆一个仓库 /themes/hexo-theme-huhu (从另一个 rope 克隆过来的)

在使用 git add . 命令时遇到问题,报错信息如下:

warning: adding embedded git repository: themes/hexo-theme-huhu
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint: 
hint:   git submodule add <url> themes/hexo-theme-huhu
hint: 
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint: 
hint:   git rm --cached themes/hexo-theme-huhu
hint: 
hint: See "git help submodule" for more information.

push 完之后,在 GitHub 上会显示如下图的图标,代表这是一个子模块,但是不知道这个模块仓库所在的 url ,因此在 GitHub 上无法打开这个文件夹。

解决方案

不使用 git submodule 功能,而是直接将这个文件夹作为根仓库的内容加入并 commit 。

1、删除已经 staged 过的文件:

git rm --cached themes/hexo-theme-huhu

2、查看当前状态:

On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        deleted:    themes/hexo-theme-huhu

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        themes/hexo-theme-huhu/

3、重新 stage 这个文件夹

git add themes/hexo-theme-huhu/

注意:这里最后一定要加上  / ,表示将这个文件夹加入,而不是将这个文件夹当做一个子模块。

两者区别:

git add themes/hexo-theme-huhu/ : create mode 100644

git add themes/hexo-theme-huhu : create mode 160000

4、再次执行 add 、 commit,并 push ,这样就可以正常 push 上去了。

引申

因为我没有 hexo-theme-huhu 这个仓库的 push 权限,所以直接使用包含文件夹的形式更为方便。

其实 git 的 submodule 功能特别强大,能够将父仓库与子仓库分开管理。

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值