当我同时拉出一个Git子模块仓库及其封闭的仓库时,为什么要提交本地更改? [英] When I pull both a Git submodule repo and its enclosing repo, why do I then have local changes to commit?

查看:91
本文介绍了当我同时拉出一个Git子模块仓库及其封闭的仓库时,为什么要提交本地更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个Git存储库R,它的子目录是子模块存储库SR.

Let's say I have a Git repo R that has a subdirectory that is a submodule repo, SR.

在机器A上,我对SR进行了更改.我承诺/推动他们.如果我上移到父目录,则git status将显示存在本地更改. (据我所知)是因为gitlink已更新,因为子仓库已更改,因此需要提交并检入.因此,我要进行提交和推送.

On machine A I make changes to SR. I commit/push them. If I move up to the parent directory, git status will show that there are local changes. This (so far as I'm aware) is because the gitlink has been updated because the subrepo changed, and this needs to be committed and checked in. So I carry out the commit and push.

在机器B上,我转到SR目录并执行git pull.然后,我转到存储库R中的封闭文件夹(也在计算机B上)并执行git pull.

On machine B I go to the SR directory and execute a git pull. I then go to the enclosing folder in repo R (also on machine B) and execute a git pull.

尽管未在计算机B上进行任何本地更改,但是git status将报告该子仓库具有(新提交),即,似乎希望我提交这些新更改.但为什么?这些变化"对谁有好处?我可以理解SR的变化构成R的变化的想法.但是,如果我同时对B进行拉动,为什么我不是100%保持最新,为什么我显然会有自己的本地变化,需要被承诺吗?

Despite having made no local changes on machine B, git status will report that the subrepo has (new commits), i.e. it seems to expect me to commit these new changes. But why? For whose benefit are these "changes"? I can get my head around the idea of the changes to SR constituting a change for R. But if I've pulled both on B, why am I not 100% up to date, and why do I apparently have my own local changes that need to be committed?

推荐答案

我可以理解SR的变化构成R的变化的想法.

I can get my head around the idea of the changes to SR constituting a change for R.

这是因为R引用SR作为 gitlink (

That is because R references SR as a gitlink (special entry in the index of the parent repo), which represents the new SHA1 of SR.

如果您希望其他克隆R的人在正确的SHA1处获得SR,则需要添加,提交和推送该新条目.

You need to add, commit and push that new entry if you want others cloning R to get back SR at the right SHA1.

这意味着在B上,您不必从SR进行git pull:它应该已经在正确的提交中签出了.

That means on B, you should not have to do a git pull from SR: it should already be checked out at the right commit.

如果我在R上执行上拉,为什么这不自动执行子模块更新?为什么这需要单独执行?执行SR时,到SR的gitlink是否不是R状态的一部分,而R状态会更新?

If I execute a pull on R, why doesn't this automatically carry out the submodule update? Why does this need to be a separate action? Is the gitlink to SR not a part of the state of R that gets updated when I execute the pull on it?

因为拉R仅更新SR gitlink,而不更新实际签出的子模块SR.

Because a pull on R only update SR gitlink, not the actual checked out submodule SR.

注意:如果您始终必须在子模块中进行拉取,则可以确保SR 关注自己的master分支.

Note: if you always have to do a pull inside a submodule, you could instead make sure SR follows its own master branch.

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

这样,一个简单的git submodule update --remote就足以从R中提取和更新SR.
像往常一样,如果SR更新其HEAD,则需要从R添加,提交和推送其新的gitlink.

That way, a simple git submodule update --remote would be enough to pull and update SR from R.
As usual, if SR updates its HEAD, you will need to add, commit and push its new gitlink from R.

这篇关于当我同时拉出一个Git子模块仓库及其封闭的仓库时,为什么要提交本地更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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