Git Subtree. Why can't I branch from a subtree rather than the root?
I am struggling trying to make sense of using the Git subtree strategy. My intent was to pull some disparate repos together into a little family of toy repos under an umbrella repo. I'm using the subtree strategy detailed here: http://help.github.com/subtree-merge
I am pulling my h开发者_JS百科air out trying to convince Git that I want to create a branch from one of these subtrees NOT from the root. When I cd into a subtree, create the branch, and then cd back to the root, running git branch from the root clearly indicates the branch was created at the root. Sigh.
I love git/github but it is maddening getting this seemingly routine task to work properly.
Could someone please enlighten me?
git works at the 'whole' tree level only, so wherever you are in your working tree operations like branch
, checkout <branch>
, commit
all work at the root level.
The subtree merge strategy is a merge strategy to help when you have a repository where one branch has moved a subtree of files to a different place in the repository and another side has made changes to those files in the original locations. It's designed to help merge these two operations in a way that a normal merge strategy would generate more conflicts or leave files in the wrong place.
The subtree merge strategy has no bearing on the way the 'whole tree' operation of git works, so if you want make a branch that is just one subtree of a repository, you need to branch then make a new commit with the other subtrees removed and the tree of interest moved up to the root level.
Given your usage pattern, though, I would recommend that you have long read up on submodules. It may provide functionality that suits what you are trying to achieve.
I recommend apenwarr's git-subtree: http://github.com/apenwarr/git-subtree. Hopefully it gets added to git itself at some point.
精彩评论