Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to checkout old git commit including all submodules recursively?

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.

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.

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

Is there anyway to do this?

like image 300
Ben Baron Avatar asked Feb 27 '13 23:02

Ben Baron


People also ask

How do I checkout an older commit?

To pull up a list of your commits and their associated hashes, you can run the git log command. To checkout a previous commit, you will use the Git checkout command followed by the commit hash you retrieved from your Git log.

How do I recursively update a submodule?

If you already cloned the project and forgot --recurse-submodules , you can combine the git submodule init and git submodule update steps by running git submodule update --init . To also initialize, fetch and checkout any nested submodules, you can use the foolproof git submodule update --init --recursive .

How do you recursively pull a Submodle?

To pull everything including the submodules, use the --recurse-submodules and the --remote parameter in the git pull command .

How fetch all commits?

Use git pull --unshallow and it will download the entire commit history. Show activity on this post. Alternatively, you can also run git fetch --depth=1000000 .


1 Answers

You need two commands to achieve this:

git checkout *oldcommit* git submodule update --recursive 

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

like image 54
Chronial Avatar answered Sep 24 '22 16:09

Chronial