编辑 git 子模块
这可能吗?想象一下我有一个项目“Parent &”孩子。两者都是 git 存储库。 Child 是 Parent 的子模块。
我可以编辑 Parent 和 Parent 中的 Child 版本吗?提交&就像常规存储库一样推送它们?
或者我是否需要在某个地方单独克隆 Child 并进行更改?
谢谢。
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 separate clone of Child somewhere that I make changes to?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不需要单独的克隆。子模块文件夹是一个独立的世界。只需编辑、提交、分支和推送即可让您满意。
Git 在这方面就很棒。 :-)
顺便说一句,父存储库甚至会检测子模块文件夹内何时发生更改,并让您提交子模块的当前状态作为父存储库克隆的新官方参考点。
重要提示:
在开始黑客攻击之前,请确保在子模块文件夹中执行
git checkout master
(或其他一些分支)。然后还要确保当您提交子模块的更新状态时,您要么将这些提交推送到公共存储库,或者至少不重新设置或以其他方式更改子模块内的历史记录之后的子模块 - 因为这会破坏父模块对子模块历史记录的引用。
小心行走。 (向 @pjmorse 致敬,以提醒您。)
底线:
是的。在子模块文件夹中进行开发是可能的,而且通常很方便,但并非没有风险。明智地选择您的开发模式
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
根据 文档:
据我所知,如果您正在添加子模块的分支上工作,则可以编辑 Child 并将其推回到其存储库。但是,如果您不是将 Child 添加到 Parent 的开发人员,那么您正在使用独立的头,并且需要签出 Child 的单独版本来进行更改,或者进行更改并导出补丁(使用
git format-patch
)供其他人提交(通过git am
)。According to the documentation:
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 (viagit am
).