git子模块检出相同的提交 [英] git submodule checks out the same commit

查看:144
本文介绍了git子模块检出相同的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我 git子模块更新后,它总是检出相同的提交。例如 34561

After I git submodule update it always checks out the same commit. for example 34561.

我做 git checkout master 为子模块,然后 git submodule sync 。然后它指向最新的提交 a2344

I do git checkout master for submodule and then git submodule sync. Then it points to the latest commit a2344.

但是在 update 它再次指向提交 34561

But after update it again points to the commit 34561.

如何更改它?我的意思是为什么它决定指出那个提交而不是另一个?

How to change it? I mean why it decided to point to that commit and not another?

推荐答案


我的意思是为什么它决定指向那个提交而不是另一个?

I mean why it decided to point to that commit and not another?

因为子模块始终在父回购中记录一个固定的SHA1提交作为 gitlink 索引中的特殊条目 )。

这就是为什么子模块总是作为分离的HEAD分支进行恢复的原因

Because a submodule always records a fixed SHA1 commit in the parent repo as a gitlink (a special entry in the index).
That is why a submodule is always restored as a detached HEAD branch

您可以将子模块配置为遵循分支

You can configure a submodule to follow a branch

cd /path/to/your/parent/repo
git config -f .gitmodules submodule.<path>.branch <branch>

子模块仍然会恢复为固定提交,但可以使用

The submodule would still be restored to a fixed commit, but can then be updated with:

git submodule update --remote

请确保在父回购库中添加并提交新的gitlink (因为将子模块更新为分支机构的最新版本会更改其SHA1,并记录在父回购库中作为gitlink )。
如果你不这样做,你会发现你的子模块回到之前的状态,然后在下一个 git submodule update --init

Make sure to add and commit the new gitlink in the parent repo (since updating a submodule to the latest of a branch would change its SHA1, recorded in the parent repo as a gitlink).
If you don't, you will find back your submodule to its previous state at then next git submodule update --init.

请参阅 Git子模块:指定分支/标记

这篇关于git子模块检出相同的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆