How to go to a specific commit using git-subtree?

I am using Avery Pennarun git -subtree, which is an extension to git.

How can I select a commit from subrepo to my main repo using git subtree? Also, how do I get to a specific commit in the subrepo history after I have already executed the git subtree for this prefix?

I basically run this in squash lock mode.

+8
git git-subtree cherry-pick
source share
1 answer

how to go to a specific fixation in the history of subrepost?

If you crushed commits, then there is no way, as squash loses different commits.

Otherwise, with an unsplit subtree, you can go to any commit of the subtree using the same hash that it has in the original repository from which the subtree was created.

git subtree (without squash) actually adds to your repository all the relevant commits from the external repository as an independent tree in your current repo. When you do git subtree add , you may notice that several commits are added (all the original commits from the external repo) and the last merge that moves the contents from this subtree to the specified directory specified with the --prefix option. In a nutshell, it checks the branch from another unrelated repository and then merges it into your current branch, moving all the contents to this subfolder.

All this means that the history of the external repo is available to you, you can check it that way, bearing in mind that being a completely different tree, this check is likely to change ALL the contents of your workspace, which can be long for large projects.

This will lead us to the second:

How am I cherry - choose commit from subrepo to main repo using git subtree?

It seems that there is no current "cherrypicking" supported by git subtree on its own. But, given the consequences of all of the above, the following can be done.

 # move yourself to the subtree commit of your choice git checkout <subtree-hash> # fetch commits from the subtree repository, to have available the commit you want # to cherry pick. git fetch <path-to-remote> # cherry pick the hash you want git cherry-pick <cherry-hash> # move back to your original branch git checkout <your-branch> # subtree merge your cherry pick (using the previous HEAD), # so that it gets moved to the correct location specified by prefix. git subtree merge --prefix <subtree-prefix> HEAD@{1} # Since you probably fetched more commits that you needed from # the remote, you might want to clean those that where not needed git gc 

Bear in mind that after this, if you try git subtree pull add an update to your subtree and enable the commit you selected cherry, you will end the conflict, since you will have two changes in one place.

Another simpler option, if you have access to the original subtree repository, is to make a cherry pick in the branch, and then just git subtree pull this specific branch.

+5
source share

All Articles