开发一个Git库项目这也是另一个项目的子模块 [英] Developing a Git library project that's also a submodule of another project

查看:183
本文介绍了开发一个Git库项目这也是另一个项目的子模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Android应用程序,这使得利用我自己的一个单独的库项目。这两个项目都存储在独立的Git仓库。该应用程序项目由 .gitmodules 文件来引用库项目。

I have an Android application under development which makes use of a separate library project of my own. These two projects are stored in separate Git repositories. The application project references the library project by means of the .gitmodules file.

我现在试图在这两个项目的共同合作在新机器上(应用程序和库)。我克隆应用程序项目,这也造成了库项目被自动克隆到我的〜/的git /目录中。到现在为止还挺好。

I'm now trying to work on both of these projects together (the application and the library) on a new machine. I cloned the application project, which resulted also in the library project being automatically cloned into my ~/git/ directory as well. So far so good.

我还请注意,在Eclipse Package Explorer中,库项目的root有括号内提交哈希值(例如 [MyLibraryName 0123ABC] )。这presumably意味着磁带库的克隆是从某一个提交点,而据我所知,我可以更新这个(即拉在最新提交该库)使用 git的子模块的foreach混帐拉

I notice also that in Eclipse Package Explorer, the library project root has a commit hash within brackets (e.g. [MyLibraryName 0123ABC]). This presumably means that the library clone is from a certain commit point, and I understand that I could update this (i.e pull in the latest commits for this library) using git submodule foreach git pull.

问题是,什么是我单独继续现在开发库项目的最佳方式?我试图修改文件和阶段,它,但使用Team->提交的时候,对话没有列出修改过的文件。我想这可能是是与它是一个子模块,在一个特定的指向提交。

Question is, what is the best way for me to continue separately developing the library project now? I tried to modify a file and stage it, but when using Team->commit, the dialogue didn't list the modified file. I assume this might be something to do with it being a submodule, pointing at a particular commit.

我应该重新克隆我的图书馆项目,完全分开到不同的子目录,进口作为一个单独的项目到Eclipse为了让我做对即图书馆工作?

Should I clone my library project again, completely separately into a different subdirectory, and import as a separate project into Eclipse in order for me to do work on that library?

推荐答案

看了其他各种做题,看来显然,有这种没有优雅的解决方案。我最终走上来解决这个步骤是:

Having read various other SO questions, it seems apparent that there's no elegant solution for this. The steps I eventually took to solve this are:


  • 假设没有这样做,克隆应用程序库,使得使用子模块。导入所有项目到Eclipse工作区,包括子模块库(或库)。请注意,子模块库是主要的应用程序库中的资料库,它不是在一个特定的分支;它是一个特定的提交(分离的头)的引用。

  • Assuming not done so already, clone the application repository that makes use of submodules. Import all projects into Eclipse workspace, including the submodule repository (or repositories). Note that the submodule repository is a repository within the main application repository, and it's not on a particular branch; it's a reference to a particular commit (detached head).

在Package Explorer中,重命名导入的子模块项目。我给它涉及到申请回购它的内部名称。例如,对于所谓的ABCD的应用项目,从SomeLibrary其重命名为SomeLibrary_ABCD。

In the Package Explorer, rename the submodule project that was imported. I gave it a name that relates to the application repo it's inside of. For instance, for an application project called ABCD, rename it from SomeLibrary to SomeLibrary_ABCD.

接下来,从自己的Git仓库分别克隆库。现在,重命名子模块项目的一点是,它现在可以从库库的独立克隆导入Eclipse项目,不使用Eclipse提供了部分或所有项目无法因为他们已经在工作区中存在进口的错误

Next, clone the library separately from its own Git repository. Now, the point of renaming the submodule project is that it's now possible to import the Eclipse project from the standalone clone of the library repository, without Eclipse giving the "Some or all projects can not be imported because they already exist in the workspace" error.

这样做之后,我们SomeLibrary_ABCD项目,这是不是一个分支,但指向特定的提交和项目是ABCD的一个子模块。那子模块使用更新的 git的子模块的foreach混帐拉。然后,我们有项目SomeLibrary,这是一个分支(例如主站)。

Having done this, we have SomeLibrary_ABCD project which is not on a branch but points to a particular commit, and is a submodule of project ABCD. That submodule is updated using git submodule foreach git pull. Then, we have project SomeLibrary, which is on a branch (e.g. master).

我的计划工作流程是本地切换应用程序项目在图书馆我的独立,而不是项目的子模块版本来点时,我想对图书馆的发展。然后,我将更改提交到SomeLibrary。

My planned workflow is to locally switch the application project to point at my 'standalone' project of the library instead of the submodule version when I want to do development on the library. I then commit changes to SomeLibrary.

任何比这更好的建议(或修正任何我说)将AP preciated - 但现在,这是我自己的答案的问题。

Any better suggestions than this (or corrections to anything I've stated) would be appreciated - but for now this is my own answer to the problem.

这篇关于开发一个Git库项目这也是另一个项目的子模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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