如何git checkout commit并使子模块更新到该提交? [英] How to git checkout commit and have submodules update to that commit?
问题描述
我正在克隆一个带有子模块的项目,并恢复到大约一年前的提交:
I'm cloning a project with submodules and reverting to a commit from about a year ago:
$ git clone --recursive --branch 5.6 https://codereview.qt-project.org/pyside/pyside-setup
$ cd pyside-setup
$ git checkout 8913156381b7dc51f903b9e459c143fb25097cab
M sources/pyside2-examples
M sources/pyside2-tools
Note: checking out '8913156381b7dc51f903b9e459c143fb25097cab'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at 89131563... Adding sync.profile file for Qt CI usage
如果我进入git子模块之一,则它们为空:
If I go down into one of the git submodules, they are empty:
$ ls -alh sources/pyside2
total 0
drwxr-xr-x 2 fredrik staff 68B Aug 11 00:12 ./
drwxr-xr-x 7 fredrik staff 238B Aug 11 00:12 ../
检出子模块时(在主项目中)8913156381b7dc51f903b9e459c143fb25097cab
时,检出子模块的最佳方法是什么?
What's the best approach to checkout the submodules as they were at the time of commit 8913156381b7dc51f903b9e459c143fb25097cab
(of the main project)?
在这种情况下,我只有两个子模块.但是,如果项目中有更多子模块怎么办?
In this particular case, I only have two submodules. But what if the project had many more submodules?
编辑#1:我使用的是Git 2.14.1.
EDIT #1: I'm on Git 2.14.1.
我可以在8913156381b7dc51f903b9e459c143fb25097cab
I can view the main project's commit details at 8913156381b7dc51f903b9e459c143fb25097cab
in the git web viewer, here. If I click the "tree" link (next to the "tree" hash), I can view the project at that commit. Traversing down to submodules sources/pyside2
and sources/shiboken2
, I see that they were both at commit c764273e64896215730e44eb907cd3535596ade4
at that time.
但是,如果我手动尝试检出这些子模块,则它们的目录仍然完全为空:
But if I manually try to checkout those submodules, their directories are still completely empty:
$ cd sources/pyside2
$ git checkout c764273e64896215730e44eb907cd3535596ade4
HEAD is now at c764273e... Fix OS/X inclusion of framework headers.
$ ls -alh
total 0
drwxr-xr-x 2 fredrik staff 68B Aug 11 00:12 .
drwxr-xr-x 7 fredrik staff 238B Aug 11 00:12 ..
推荐答案
至少尝试:
cd /path/to/main/project
git submodule update --init --recursive
那应该能够在正确的SHA1上克隆您的子模块
That should be able to clone your submodule at the right SHA1
这篇关于如何git checkout commit并使子模块更新到该提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!