简体   繁体   English

在带有子模块的 git 存储库中分支

[英]Branching in a git repo with submodules

Say I create a git repo with a submodule in it.假设我创建了一个 git 存储库,其中包含一个子模块。 Then I clone the repo (with the submodule) and create a branch in my local repo.然后我克隆存储库(带有子模块)并在我的本地存储库中创建一个分支。 Will that branch include the submodule?该分支会包含子模块吗? If I change 2 files in the repo, f1 an f2, with f1 in the submodule and f2 outside of the submodule, and then commit my change, will that commit include both files?如果我在 repo 中更改了 2 个文件,f1 和 f2,f1 在子模块中,f2 在子模块之外,然后提交我的更改,该提交会包括这两个文件吗? If I then push the commit, will that change the remote submodule?如果我然后推送提交,那会改变远程子模块吗?

  1. Your new branch will include submodule.您的新分支将包含子模块。
  2. Submodule - is a separate repository.子模块 - 是一个单独的存储库。 So in order to save changes, you need to commit first of all to submodule repository.因此,为了保存更改,您需要首先提交到子模块存储库。 Then, you could commit to your main repository that submodule has been changed.然后,您可以向您的主存储库提交该子模块已更改的内容。 Overall, "main" repository points to some specific commit of submodule repository.总体而言,“主”存储库指向子模块存储库的某些特定提交。
cd SubmoduleRepo
git commit --all -m "Change submodule code" // commit changes directly to submodule repo
git push submodule_origin // push changes to remote submodule repo
cd .. // go back to main repository working folder

git add SubmoduleRepo // commit that submodule repo was changed
git commit -m "Updated submodule" 
git push origin // push changes for the main repo

Yes it will include the submodule but it will not commit f1 to the submodule's repo.是的,它将包含子模块,但不会将 f1 提交到子模块的存储库。

Think of submodule as a subrepo.将子模块视为子存储库。 It is a separate repository REFERENCED in your current repo.它是您当前存储库中引用的单独存储库。 Imagine that many team/repo is referencing/using that repository via submodule too.想象一下,许多团队/repo 也通过子模块引用/使用该存储库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM