I have a submodule on a different branch (branch-with-submodule) and currently on a branch without one (branch-without-submodule) as such.
---(Commit that adds submodule)-A-B-[branch-with-submodule]
\
--C-[branch-without-submodule*]
What can I do if I want the submodule in the current branch? I guess I can just cherry-pick
the commit that adds the submodules but what if there are many other modifications in that commit (say, there are multiple submodules) and I only need one particular submodule?
Is there any way to achieve this without manually adding the git submodule again? Perhaps using checkout
?
git cherry-pick
is your best bet, although this is arguable.
If this is not an option because the commit is dirty, there's always the option to split it into several different commits. BTW, this is exactly the reason why you should commit often and push one. Commits are free and is easy to squash them, but splitting them requires an history revision.
git merge
is also a viable way, but I believe you don't want to go there, because you just want that one .gitmodules addition. So, rebasing is a no go as well.
One final note: if you can't cherry-pick because that commit has the one submodule you need and other files you don't want, you may always cherry-pick only certain files. Since these are submodules, though, I'm not 100% it will work.