开发者

Editing a git submodule

Is this possible? Imagine I have projects Parent & Child. Both are git respositories. Child is a submodule of Parent.

Can I make edits to the version of Child that is inside Parent & commit & push them just like a regular repository?

Or do I need a s开发者_JAVA百科eparate clone of Child somewhere that I make changes to?

Thanks.


You don't need a seperate clone. The sub-module folder is a world of its own. Just edit, commit, branch, and push to your heart's delight.

Git is great that way. :-)

BTW, the parent repository will even detect when changes happen inside the sub-module folder and offer you to commit the current state of the sub-module as the new official reference point for clones of the parent repo.

Important note:

Make sure you do git checkout master (or some other branch) inside the sub-module folder before your start hacking.

Then also make sure when you commit the updated state of the sub-module, that you either push those commits to a public repo, or at least that you don't rebase or otherwise change the history inside the sub-module afterwards - as that would corrupt the parent's reference to the sub-module's history.

Tread with care. (Hat tip to @pjmorse for the reminder.)

Bottomline:

Yes. Developing within a submodule folder is possible and often convenient but not without its risks. Choose your development model wisely


According to the documentation:

If you want to make a change within a submodule, you should first check out a branch, make your changes, publish the change within the submodule, and then update the superproject to reference the new commit.

As near as I can tell, if you're working on the branch where the submodule was added, you can edit Child and push back to its repository. But if you're not the developer who added Child to Parent, you're working with a detached head and will need to either check out a separate version of Child to make changes, or make the changes and export the patches (using git format-patch) for someone else to commit (via git am).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜