你如何与git子模块一起发展? [英] How do you develop along with a git submodule?
问题描述
这是我的项目结构
MainProject
| README.md
| src /
| lib /#这是一个子模块
当我开发 MainProject
,我还会开发 lib /
,我的意思是 MainProject / lib /
。
当我推送时,我会将 MainProject / lib / *
中的所有更改复制到 MainProject /../中lib /
,这是一个单独的git目录,然后push。
之后,我将在 MainProject / lib /
到远程的最新版本。
然后,我将提交并推送 MainProject
中的更改。
它受到影响。你如何与git子模块一起开发?
ADD 我想要将 / code>,他会得到最新消息吗? 我的 必须复制您的更改:您可以直接从 但是,您必须返回 在 否:当您在lib中提交anyhting时,会改变 gitlink ( 通过回到 但是推送 Here is my project structure When I develop When I do push, I will copy all changes in After that I will do a submodule update in Then I will commit and push changes in It suffers. How do you develop along with a git submodule? ADD I want all changes in So if I directly put to remote If someone else clone My
You shouldn't have to copy your changes: you can push directly from But then, you have to go back to
lib /
中的所有更改推送到远程 lib
存储库。
将 MainProject
中的 lib /
旁的所有更改推送到远程 MainProject < code $。
因此,如果我直接将远程 lib
存储库放入 MainProject / lib
然后在 MainProject $ c中添加并提交并推送
lib /
旁边的更改如果其他人克隆 MainProject
并且执行子模块更新<$ c $>到远程。
.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
MainProject
中的'lib'索引)
MainProject
(也就是说,您位于 MainProject / lib
,你做 cd ..
),你可以做一个git add。,它会:
lib /
子模块关联的新SHA1(' lib
'gitlink entry)
MainProject $ c $你可以确保任何克隆你的
MainProject
的人都会得到 lib
在那个确切的更新的SHA1。MainProject
| README.md
| src/
| lib/ # this is a submodule
MainProject
, I will also develop lib/
, I mean MainProject/lib/
.MainProject/lib/*
into MainProject/../lib/
, which is a separate git directory, then push.MainProject/lib/
to latest from remote. MainProject
.lib/
pushed to remote lib
repository.
And all changes beside lib/
in MainProject
pushed to remote MainProject
.lib
repository inside MainProject/lib
And then add and commit and push changes beside lib/
in MainProject
to remote.MainProject
and do submodule update
, will he get the latest sources?.gitmodules
: [submodule "lib"]
path = lib
url = git@github.com:XXX/YYY.git
branch = master
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.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/
inMainProject
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屋!