如何将对子模块所做的更改提交到主git repo中? [英] How to push commits from changes made to a submodule into main git repo?

查看:124
本文介绍了如何将对子模块所做的更改提交到主git repo中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定将我的应用程序存储库从SVN切换到git.

I have decided to switch from SVN to git for my app repository.

我的回购结构如下:

~/AndroidStudioProjects/MyMine $ tree -L 1
.
├── ActionBarSherlock
├── Android-Universal-Image-Loader
├── Android-ViewPagerIndicator
├── Crouton
├── ListViewAnimations
├── MyMine
├── SlidingMenu
├── aFileChooser
├── drag-sort-listview
└── out

10 directories, 0 files

如您所见,我有很多库,我的应用程序的核心位于MyMine文件夹中.

As you can see, I have plenty of libraries, and the core of my app is in the MyMine folder.

我已将库添加为git子模块:

I have added the libraries as git submodules:

~/AndroidStudioProjects/MyMine $ cat .gitmodules
[submodule "ActionBarSherlock"]
    path = ActionBarSherlock
    url = https://github.com/JakeWharton/ActionBarSherlock.git
[submodule "Android-Universal-Image-Loader"]
    path = Android-Universal-Image-Loader
    url = https://github.com/nostra13/Android-Universal-Image-Loader.git
[submodule "Android-ViewPagerIndicator"]
    path = Android-ViewPagerIndicator
    url = https://github.com/JakeWharton/Android-ViewPagerIndicator.git
[submodule "Crouton"]
    path = Crouton
    url = https://github.com/keyboardsurfer/Crouton.git
[submodule "drag-sort-listview"]
    path = drag-sort-listview
    url = https://github.com/bauerca/drag-sort-listview.git
[submodule "ListViewAnimations"]
    path = ListViewAnimations
    url = https://github.com/nhaarman/ListViewAnimations.git
[submodule "SlidingMenu"]
    path = SlidingMenu
    url = https://github.com/jfeinstein10/SlidingMenu.git
[submodule "aFileChooser"]
    path = aFileChooser
    url = https://github.com/iPaulPro/aFileChooser.git

现在,假设我对库/子模块之一进行了更改.但我不想将这些更改推到其来源,因为:

Now, let's say I make changes to one of the libraries/submodules. But I don't want to push those changes to their origin, because:

  • 作者可能/将拒绝我的承诺
  • 我的更改仅与我有关
  • 我所做的更改只是单行修改,可以适应代码,以便在我的项目中进行编译

但是,我要做的是将我的提交(对那些子模块所做的)推送到项目的原始位置.这是因为这些更改对于编译我的项目是必需的.因此,如果我决定将完整的存储库克隆到新的开发计算机上,那么我希望它们成为存储库.或者,如果有新人加入团队并需要设置其开发机器.

However, what I do want is to push my commits (made to those submodules) to my project's origin. This is because those changes are necessary for compiling my project. So I want them to be in the repo if I decide for example to clone the full repo to a new development machine. Or if a new guy comes to the team and needs to setup its development machine.

那么,那么,我已经承诺对其中一个库进行修改.然后,我将相应的子模块提交到我的存储库中,并将其推到原始位置.

So, then, I have committed the modifications made to one of the libraries. Then, I committed the corresponding submodule to my repository, and pushed it to the origin.

问题是,在(我的服务器的)原始服务器上,子模块项目指向错误的快照,因为该快照仅存在于我的本地存储库中,而不存在于原始存储库中.而且我无法推送,因为git会尝试将提交推送到子模块的来源,这不是我项目的来源.

The problem is that on the origin (of my server), the submodule projects points to a wrong snapshot, because that snapshot is only existing on my local repo, and not on origin's. And I can't push that, because git would try to push the commits to the submodule's origin, which is not my project's origin.

我如何提交对子模块所做的更改,并使这些更改可从主存储库中获得?所有这些都没有将子模块推向原点?

How can I commit changes made to a submodule, and have those changes available from my main repository? All of that without pushing the submodule to its origin?

对于所使用的术语或方法似乎愚蠢或不合适,我深表歉意.就像我说的那样,我正在尝试切换到git,即使我花了一些时间阅读git书,也可能误解了一些过程或词汇.

I apologize if the terminology or the methods I use seem dumb or aren't appropriate. As I said, I'm trying to switch to git, and even if I spent some time reading a git book, I may have misunderstood some of the processes or vocabulary.

推荐答案

据我所知您不能这样做.

You can't do that, as far as I know.

您将需要派生子模块存储库,并将项目的子模块指向派生而不是当前位置.然后,您可以将更新推送到fork中,并在其中进行维护,您的主项目可以指向您的更改.

You'll need to fork the submodule repo and point your project's submodule at the fork instead of the current location. Then you can push your updates to your fork, maintain them there, and your main project can point to your changes.

您还有另一种选择,就是将更改作为补丁维护,并让编译系统在编译之前应用它们.

The other option you have is to just maintain your changes as patches and have your build system apply them before compiling.

也许有人会为您提供一个巧妙的把戏.

Maybe someone will come along with a neat trick for you.

这篇关于如何将对子模块所做的更改提交到主git repo中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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