如何以递归方式检出包括所有子模块的旧git commit? [英] How to checkout old git commit including all submodules recursively?

查看:51
本文介绍了如何以递归方式检出包括所有子模块的旧git commit?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有多个子模块的git repo.这些子模块之一具有自己的多个子模块.我要做的就是在主存储库上签出旧的提交,并从所有子模块中签出适当的提交,以在那时获得正确的代码状态.

I have a git repo with multiple submodules. One of those submodules has multiple submodules of it's own. All I'm looking to do is check out an old commit on the master repo and have it checkout the appropriate commits from all submodules to get the correct state of the code at that time.

我知道git包含必要的信息,因为 ls-tree 命令可以告诉我每个子模块在哪个提交上.但是,我必须手动检查每一个,这非常耗时.

I know that git contains the information necessary as the ls-tree command can tell me which commit each submodule was on. However, I have to manually check out each one, which is painfully time consuming.

我正在寻找类似 git checkout --recursive 之类的东西,但是这样的命令似乎不存在.

I'm looking for something like git checkout --recursive but such a command doesn't seem to exist.

反正有这样做吗?

推荐答案

您需要两个命令来实现:

You need two commands to achieve this:

git checkout *oldcommit*
git submodule update --recursive


更新:该答案截至2018年已过时-请参见


Update: This answer is outdated as of 2018 – see VonC's answer below for more current information.

这篇关于如何以递归方式检出包括所有子模块的旧git commit?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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