Reputation: 10281
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
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 ../
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?
EDIT #1: I'm on Git 2.14.1.
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 ..
Upvotes: 5
Views: 528
Reputation: 1324148
Try at least:
cd /path/to/main/project
git submodule update --init --recursive
That should be able to clone your submodule at the right SHA1
Upvotes: 4