前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >git仓库包含子仓库时,add报错的解决办法

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

作者头像
德顺
发布2020-02-14 15:41:21
11.6K0
发布2020-02-14 15:41:21
举报
文章被收录于专栏:前端资源前端资源

本文主要介绍在一个仓库内部克隆另外一个仓库,后续该如何进行管理。最近在尝试使用 Hexo 博客,在添加主题后使用 git 的 add 命令时报错。

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

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

代码语言:javascript
复制
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 过的文件:

代码语言:javascript
复制
git rm --cached themes/hexo-theme-huhu

2、查看当前状态:

代码语言:javascript
复制
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 这个文件夹

代码语言:javascript
复制
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 功能特别强大,能够将父仓库与子仓库分开管理。

关于 submodule 的使用推荐详细地读一下 Pro Git:中文版英文版

声明:本文由w3h5原创,转载请注明出处:《git仓库包含子仓库时,add报错的解决办法》 https://cloud.tencent.com/developer/article/1583762

本文已加入 腾讯云自媒体分享计划 (点击加入)

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 解决方案
  • 引申
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档