I am using Avery Pennarun’s git-subtree which is an extension to git.
How do I cherry-pick a commit from a sub-repo into my main repo using git subtree? Also how do I go to a specific commit in the history of the sub-repo after I have already done a git subtree pull on that prefix?
I am primarily running this in the squash commits mode.
If you have squashed the commits, then there is no way, since the squash looses the different commits.
Otherwise, with a un-squashed subtree, you can navigate to any commit of the subtree with just the same hash that it has in the original repository from which the subtree was created.
git subtree(without the squash) actually adds into your repository all the relevant commits from the external repository as an independent tree within your current repo. When you do agit subtree addyou can notice that several commits are added (all the original commits from the external repo) and a last merge commit that moves the content from that subtree to the given directory specified with the--prefixoption. In a nutshell, it checks out a branch from another unrelated repository and then merges it into your current branch by moving all that content into a given subfolder.All this means is that the history of the external repo is available to you, you can checkout to it just like that, having in mind that by being a completely different tree this checkout will probably modify ALL the contents of your workspace, which on big projects can be lengthy.
This moves us to the second:
Seems like there is not current “cherrypicking” supported by
git subtreeon itself. But given the implications of all the above the following can be done.Take into consideration that after doing this if you try to
git subtree pullinto your subtree an update, and it includes the commit you cherry picked, you will end with a conflict since you will have two changes in the same place.Another more simple option, if you have access to the original subtree repository, is to make the cherry pick there in a branch and then just
git subtree pullthat specific branch.