首页 > 解决方案 > 使用子模块将 git 分支合并到我的正确方法

问题描述

这一定是个骗子,但我找不到能找到答案的搜索词组。

我有一个foo带有一个子模块的 git repo (),指向abc123另一个 repo ( bar) 的提交。

我有一个长期存在的分支,foo仍然指向 commit abc123

更改发生在foomain分支上,包括对子模块的更新,将其移至 commit zyx987

现在我想合并main到我的分支中。

通常我会这样做git merge main。使用子模块,这向我展示了:

# On branch feature
# All conflicts fixed but you are still merging.
#  (use "git commit" to conclude merge)
#
# Changes to be committed:
#
#       ...
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:  bar (new commits)
#

当我导航到bar目录并执行 agit status时,我看到它仍在上一次提交 ( abc123) 中。我试过git add bar了,但它一直保持在abc123.

我发现获得新提交的唯一方法是导航到子模块的目录并手动发出git checkout zyx987.

这里显然有可能出现错误,我很容易错过子模块更改的事实,或者当我手动更新它时选择了错误的提交,更不用说这是我作为开发人员从事的额外工作(不相关) 功能分支,不需要关心该子模块中发生了什么。

git merge当您发现子模块已更改时,有没有办法说“合并并更新子模块”或(更好)在正常之后接受在源分支中选择的提交?

标签: gitmergegit-submodules

解决方案


推荐阅读