编辑 git 子模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5427414/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:14:11  来源:igfitidea点击:

Editing a git submodule

gitgit-submodules

提问by Christopher Stott

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

这可能吗?想象一下,我有父子项目。两者都是 git 存储库。Child 是 Parent 的子模块。

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

我可以像常规存储库一样编辑 Parent 中的 Child 版本并提交和推送它们吗?

Or do I need a separate clone of Child somewhere that I make changes to?

或者我是否需要一个单独的 Child 克隆来进行更改?

Thanks.

谢谢。

回答by Már ?rlygsson

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

Git在这方面很棒。:-)

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.

git checkout master在开始黑客攻击之前,请确保在子模块文件夹中执行(或其他分支)。

Then also make sure when you commit the updated state of the sub-module, that you either pushthose 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.

然后还要确保当您提交子模块的更新状态时,您将push这些提交到公共存储库,或者至少您之后没有重新设置或以其他方式更改子模块内的历史记录 - 就像那样破坏父模块对子模块历史的引用。

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

小心踩踏。(帽子提示@ pjmorse提醒。)

Bottomline:

底线:

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

是的。在子模块文件夹中开发是可能的,而且通常很方便,但并非没有风险。明智地选择您的开发模式

回答by pjmorse

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

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