Reputation: 434
I have a submodule sub
in a Git project super
. Now there are multiple branches of super
and each may point to another commit of sub
. Changing the branch of super
via
>$ git checkout <branchname>
does not properly adapt sub
to point to the correct commit again, though. Instead the result of
>$ git status
contains a modified entry for sub
.
This is only one of several situations where one might want to revert any modifications of sub
and checkout the commit to which super
actually points.
For files you can always run
>$ git checkout -- path/to/file
to revert any modifications. So I am basically looking for an equivalent call to revert submodules in a similarly quick and simple manner.
I know this is possible by combination of two commands:
>$ git submodule deinit -f /path/to/sub
>$ git submodule update --init --recursive /path/to/sub
but I am looking for a shorter version which might be easier to remember and faster to type ;)
Do you have any recommendations?
Upvotes: 0
Views: 1474
Reputation: 434
As mentioned by torek, skipping the deinit step works well. Thus the following command does the job for me:
git submodule update --recursive /path/to/submodule
Thank you all for your answers!
Upvotes: 2
Reputation: 2699
Could you please try this command and check?
git checkout --recurse-submodules {branch_name}
Upvotes: 1