如何更新git子模块

时间:2015-05-06 06:29:04

标签: git git-submodules git-merge

我刚刚在应用中完成了git merge <merging_branch_name>并解决了很多冲突。

但是当我git status时,我可以在消息中看到带有(新提交)的子模块列表。 看起来子模块(分支/标签)版本尚未更新。

例如:

modified:   plugins/myplugin.git (new commits)

如何使用版本(使用<merging_branch_name>

更新子模块

我在git bash中得到这样的结果

my_app (current_branch  |MERGING), 

所以当我git status时,我会得到以下子模块列表

 modified:   plugins/plugin1.git (new commits)
 modified:   plugins/plugin2.git (new commits)
 modified:   plugins/plugin3.git (new commits)
 modified:   plugins/plugin4.git (new commits)

我该如何解决这个问题?

3 个答案:

答案 0 :(得分:4)

要将子模块内容更新为新的SHA1,这应该足够了:

# the submodule content needs to be updated
git submodule update --init

# the parent repo needs to record the new submodule SHA1
git add plugins/myplugin

答案 1 :(得分:4)

我们假设您有两个分支masterhotifx。在master中,子模块的头部位于123456 hotfix abcdefabcdef。 (我们说123456master更新。如果您已签出hotfix并合并abcdef,则子模块头将移至git diff,但子模块中的代码不会检出此新头。如果您现在输入123456,您会看到子模块指向abcdef,但这不正确,因为您要指向git add pathToSubmodule 。 如果您现在输入

123456

将旧的git submodule update 添加到索引中。这是错误的提交。你需要做的是将头移动到正确的提交,这是通过简单的调用

来完成的
conn.execute('insert into users values(@login, @password)')

答案 2 :(得分:1)

子模块基本上指向在父git存储库中进行提交时使用的子模块中的特定提交。似乎在合并之后,子模块在合并后的预期提前。你有两个选择:

  • 返回子模块当前指向的提交
  • 更新您的父存储库以使用新的子模块状态

第一个选项被其他人指出为

git submodule update

第二个选项,我认为这是你要求的,用

完成
git add plugins/plugin?.git
git commit -m 'update submodules'

将更新您的HEAD状态以存储当前的子模块引用。

您可以通过查看

来查看发生了什么
git ls-tree HEAD | grep 'plugin1.git'

更新子模块之前和之后。将此引用与此插件中的当前提交进行比较:

cd plugins/plugin1.git
git rev-parse HEAD
相关问题