编辑 git 子模块

发布于 2024-10-26 20:32:29 字数 188 浏览 3 评论 0原文

这可能吗?想象一下我有一个项目“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天赋异禀 2024-11-02 20:32:29

您不需要单独的克隆。子模块文件夹是一个独立的世界。只需编辑、提交、分支和推送即可让您满意。

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

最好是你 2024-11-02 20:32:29

根据 文档

如果您想在子模块中进行更改,您应该首先签出分支,进行更改,在子模块中发布更改,然后更新超级项目以引用新的提交。

据我所知,如果您正在添加子模块的分支上工作,则可以编辑 Child 并将其推回到其存储库。但是,如果您不是将 Child 添加到 Parent 的开发人员,那么您正在使用独立的头,并且需要签出 Child 的单独版本来进行更改,或者进行更改并导出补丁(使用 git format-patch)供其他人提交(通过git am)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文