Checkout past git submodule commit
I am working on a project where there are a number of submodules. Yesterday, everything was peachy, app 开发者_JAVA百科was running, etc. After I ran git submodules update
this morning, I receive an error in the application.
$ git submodule update
Submodule path 'vendor/plugins/pluginA': checked out '49d5cba84dcffc061db69813162d103feef31ecb'
Submodule path 'vendor/plugins/pluginB': checked out '4f442f0448c1826252933d5af8fb33cd64d76f6e'
So how do I go about checking out the previous version of the submodule(s) while I wait for the issue to get fixed? I've seen several references to solutions without really seeing an example that specifically mentioned this case.
Thanks!
Edit: bonus if you can also help me understand/fix this (how to get the pluginA
and pluginB
to reference heads/master again):
$ git submodule status
49d5cba84dcffc061db69813162d103feef31ecb vendor/plugins/pluginA (49d5cba)
4f442f0448c1826252933d5af8fb33cd64d76f6e vendor/plugins/pluginB (4f442f0)
558fd1a762d63562689e58cac50283192fde74d5 vendor/plugins/pluginC (heads/master)
4feb2c51148ebc4d4f80f9a64b9eabbfde5b13a3 vendor/plugins/pluginD (heads/master)
19dce61e256b0fc3f05342cdd3e4d21a434c0b87 vendor/plugins/pluginE (heads/master)
$ git submodule update
Submodule path 'vendor/plugins/pluginA': checked out '49d5cba84dcffc061db69813162d103feef31ecb'
Submodule path 'vendor/plugins/pluginB': checked out '4f442f0448c1826252933d5af8fb33cd64d76f6e'
means you have done a git pull, fetching and merging files and submodules to your project.
The SHA1 of those submodules in the upstream project (the one you have been pulling of) have changed.
You can change them back (git checkout aref
within projectA
, then cd ..
and git add -A; git commit -m "advance submodule to aref"
), and push (or not) those submodules ref back to upstream if you want.
If you need to know what exact SHA1 was your submodule at before the submodule update, simply do a git show previousProjectSHA1
(previousProjectSHA1
being the previous SHA1 before your main project update
You will see something like:
new file mode 160000
index 0000000..4c4c5a2
That (4c4c5a2) is the submodule SHA1 you need to restore them to their previous state.
See git submodule update SO question to know more about the nature of submodules.
Same is for first case, you go to submodule dir and checkout what ever version you like with git checkout <ref>
精彩评论