How do you develop along with a git submodule?

╄→гoц情女王★ 提交于 2019-12-08 09:41:33

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/25562325/how-do-you-develop-along-with-a-git-submodule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!