"git submodule update --remote" 中的 "--remote" 到底是什么意思?

6

我只是不理解 Git 的帮助页面。那么会发生什么或有什么区别呢?

假设我有一个带有子模块 B 的 Git 项目 A。子模块 B 又有一个子模块 C。克隆仓库后,A 指向 B 的特定提交。而 B 又指向 C 的特定提交。

如果我在 A 中,通过以下命令进入 B:

cd B

现在我打字。
git submodule update --remote

或者

git submodule update

有什么区别吗?假设远程服务器对A、B和C进行了更改。

我猜使用"git submodule update --remote"会保持对特定版本C的引用。如果不使用--remote,会更新到最新版本的C吗?

2个回答

10

假设B是A的唯一子模块。

cd A
git ls-tree -r HEAD | grep commit

输出结果大致如下:

160000 commit 0814c6ba8f45829f04709c56118868d2483444c2 foo

foo 是子模块文件夹,0814c6ba8f45829f04709c56118868d2483444c2 是A的当前提交所跟踪的它的修订版本。

git submodule update 执行类似操作。

cd B
git checkout 0814c6ba8f45829f04709c56118868d2483444c2

git submodule update --remote 就像

cd B
git fetch origin master
git checkout origin/master

默认情况下,使用masterorigin/master。如果在.gitmodule中指定了分支为submodule.foo.branch = bar,那么使用barorigin/bar


我在Git方面还是个新手,我可以假设“git submodule update”永远不应该被使用,因为我们总是想要子模块的最新版本。 - Richard Fu
1
@RichardFu 这取决于情况。在某些情况下,您可能需要最新的修订版,在其他情况下则不需要。 - ElpieKay
你能提供一个参考吗?这个信息在 git help submodule 中没有。 - Cédric Van Rompay
1
@CédricVanRompay 请参考 https://git-scm.com/docs/git-submodule#Documentation/git-submodule.txt---remote 和 https://git-scm.com/docs/git-submodule#Documentation/git-submodule.txt---branchltbranchgt。 - ElpieKay

1

git submodule update --remote

允许您使用子模块的远程跟踪分支,而不是超级模块中记录的特定提交(也称为SHA)。

git submodule update

允许您使用超级模块中记录的特定提交。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接