你如何与git子模块一起发展? [英] How do you develop along with a git submodule?

查看:101
本文介绍了你如何与git子模块一起发展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的项目结构

  MainProject 
| README.md
| src /
| lib /#这是一个子模块

当我开发 MainProject ,我还会开发 lib / ,我的意思是 MainProject / lib /



当我推送时,我会将 MainProject / lib / * 中的所有更改复制到 MainProject /../中lib / ,这是一个单独的git目录,然后push。



之后,我将在 MainProject / lib / 到远程的最新版本。

然后,我将提交并推送 MainProject 中的更改。



它受到影响。你如何与git子模块一起开发?



ADD

我想要将 lib / 中的所有更改推送到远程 lib 存储库。
MainProject 中的 lib / 旁的所有更改推送到远程 MainProject < code $。

因此,如果我直接将远程 lib 存储库放入 MainProject / lib
然后在 MainProject lib / 旁边的更改如果其他人克隆 MainProject 并且执行子模块更新<$ c $>到远程。

/ code>,他会得到最新消息吗?



我的 .gitmodules

  [submodulelib] 
path = lib
url = git@github.com:XXX / YYY.git
branch = master


解决方案

必须复制您的更改:您可以直接从 MainProject / lib 推送到相同的上游回购库( git remote origin )比在 MainProject /../ lib 中找到的上游回购( git remote origin )。



MainProject / lib 本身就是一个嵌套的回购:您可以添加提交并直接从它推送。



但是,您必须返回 MainProject / ,添加,提交并推送以记录新的gitlink(记录子模块lib的SHA1的父回购索引中的特殊条目





lib / 旁边的更改> MainProject to remote

否:当您在lib中提交anyhting时,会改变 gitlink MainProject 中的'lib'索引)



通过回到 MainProject (也就是说,您位于 MainProject / lib ,你做 cd .. ),你可以做一个git add。,它会:




  • 在lib /
  • 上添加所有更改
  • 记录与 lib / 子模块关联的新SHA1(' lib 'gitlink entry)



但是推送 MainProject MainProject 的人都会得到 lib 在那个确切的更新的SHA1。


Here is my project structure

MainProject
|  README.md
|  src/
|  lib/      # this is a submodule

When I develop MainProject, I will also develop lib/, I mean MainProject/lib/.

When I do push, I will copy all changes in MainProject/lib/* into MainProject/../lib/, which is a separate git directory, then push.

After that I will do a submodule update in MainProject/lib/ to latest from remote.

Then I will commit and push changes in MainProject.

It suffers. How do you develop along with a git submodule?

ADD

I want all changes in lib/ pushed to remote lib repository. And all changes beside lib/ in MainProject pushed to remote MainProject.

So if I directly put to remote lib repository inside MainProject/lib And then add and commit and push changes beside lib/ in MainProject to remote.

If someone else clone MainProject and do submodule update, will he get the latest sources?

My .gitmodules:

 [submodule "lib"]
    path = lib
    url = git@github.com:XXX/YYY.git
    branch = master

解决方案

You shouldn't have to copy your changes: you can push directly from MainProject/lib to the same upstream repo (the one in git remote origin) than the upstream repo (git remote origin) found in MainProject/../lib.

MainProject/lib is a nested repo in its own right: you can add commit and push them directly from it.

But then, you have to go back to MainProject/, add, commit and push in order to record the new gitlink (the special entry in the index of the parent repo which records the SHA1 of the submodule lib)


add and commit and push changes beside lib/ in MainProject to remote

No: when you commit anyhting in lib, that will change the gitlink (the 'lib' entry in MainProject index)

By "going back to MainProject" (meaning, you were in MainProject/lib and you do cd ..), you can do a git add ., which will:

  • add all your changes beside lib/
  • record the new SHA1 associated with lib/ submodule (the 'lib' gitlink entry)

But pushing the MainProject, complete with the updated gitlink 'lib' entry, you are making sure that anyone cloning your MainProject will get back lib at that exact updated SHA1.

这篇关于你如何与git子模块一起发展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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