将通用代码添加为git子模块的问题:“索引中已经存在” [英] Issue with adding common code as git submodule: "already exists in the index"

查看:2514
本文介绍了将通用代码添加为git子模块的问题:“索引中已经存在”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是git的新手,希望能帮助您添加子模块。
我收到了两个共享一些通用代码的项目。共享代码刚刚复制到两个项目中。我为公共代码创建了一个单独的git仓库,并将其从项目中删除,并将其添加为git子模块。

我使用git submodule的路径选项add来指定文件夹:

  git submodule add url_to_repo projectfolder 

但是接到错误:

 'projectfolder'已存在于索引

这是我的仓库所需的结构:

  repo 
| - projectfolder
| - 具有公共代码的文件夹

可以直接在repo中添加git子模块,进入一个新的文件夹,但不在projectfolder。问题是,它确实需要在项目文件夹中。
我能做些什么和我误解了git submodule add的路径选项?

解决方案

恐怕没有足够的信息来确定发生了什么,因为你没有对于我的后续问题,我不回答



这个错误意味着 projectfolder 已经上演(已经存在于索引中)。要了解这里发生了什么,尝试列出该文件夹下索引中的所有内容:

  git ls-files  - stage projectfolder 

该输出的第一列将告诉您索引中 projectfolder 。 (这些看起来像Unix文件模式,但在git中有特殊含义。)



我怀疑你会看到类似于:

  160000 d00cf29f23627fc54eb992dde6a79112677cd86c 0 projectfolder 

160000 开头),在这种情况下, projectfolder 中的存储库已被添加为gitlink。如果它没有出现在 git submodule 的输出中,并且你想重新添加它作为子模块,你可以这样做:

  git rm --cached projectfolder 

...来取消它,然后:

  git submodule add url_to_repo projectfolder 

...将存储库作为子模块添加。



然而,也有可能你会看到很多列出的斑点(文件模式 100644 100755 ),这会暗示你没有在将新存储库复制到位之前,请妥善取消 projectfolder 中的文件。如果是这样,您可以执行以下操作以取消所有这些文件:

  git rm -r --cached projectfolder 

...然后添加子模块:

  git submodule add url_to_repo projectfolder 


I'm new to git and would appreciate help with adding submodules. I've received two projects sharing some common code. The shared code was just copied into the two projects. I created a separate git repo for the common code and removed it from the projects with the plan to add it as a git submodule.

I used the path option of git submodule add to specify the folder:

git submodule add url_to_repo projectfolder

but then got the error:

'projectfolder' already exists in the index"

This is the desired structure of my repository:

repo
|-- projectfolder
    |-- folder with common code

It is possible to add the git submodule directly in the repo or into a new folder there, but not in the projectfolder. The problem is that it really need to be in the projectfolder.. What can I do about this and what have I misunderstood about the path option of git submodule add?

解决方案

I'm afraid there's not enough information in your question to be certain about what's going on, since you haven't replied to my follow-up question, but this may be of help in any case.

That error means that projectfolder is already staged ("already exists in the index"). To find out what's going on here, try to list everything in the index under that folder with:

git ls-files --stage projectfolder

The first column of that output will tell you what type of object is in the index at projectfolder. (These look like Unix filemodes, but have special meanings in git.)

I suspect that you will see something like:

160000 d00cf29f23627fc54eb992dde6a79112677cd86c 0   projectfolder

(i.e. a line beginning with 160000), in which case the repository in projectfolder has already been added as a "gitlink". If it doesn't appear in the output of git submodule, and you want to re-add it as a submodule, you can do:

git rm --cached projectfolder

... to unstage it, and then:

git submodule add url_to_repo projectfolder

... to add the repository as a submodule.

However, it's also possible that you will see many blobs listed (with file modes 100644 and 100755), which would suggest to me that you didn't properly unstage the files in projectfolder before copying the new repository into place. If that's the case, you can do the following to unstage all of those files:

git rm -r --cached projectfolder

... and then add the submodule with:

git submodule add url_to_repo projectfolder

这篇关于将通用代码添加为git子模块的问题:“索引中已经存在”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆