问题
I'm trying to add a repo (called cow) to my project using git subtree add
. In particular, I'd like to add the branch stable
(which is not the master
branch). I tried:
git subtree add -P cow https://github.com/geoffryan/cow.git stable
But this returned the error
'stable' does not refer to a commit.
I also tried:
git subtree add -P cow https://github.com/geoffryan/cow.git cow/stable
'cow/stable' does not refer to a commit.
And:
git subtree add -P cow https://github.com/geoffryan/cow.git ca26d248a12c21264e32a2c212381cafb578c9fb
'ca26d248a12c21264e32a2c212381cafb578c9fb' does not refer to a commit.
The hash was that for the latest commit in the stable
branch. The examples of use I've seen online all use master
for the commit, is it possible to use subtree add
on a non-master branch?
回答1:
This seems to work
$ git remote add cow https://github.com/geoffryan/cow.git
$ git fetch cow
$ git subtree add -P cow cow/stable
Added dir 'cow'
I don't understand how to use directly the command with the repository part.
回答2:
I encounter a similar problem. However, gipi's solution doesn't work for me. Oddly, when I add master branch everythins is fine, but when I want to add other branches, it returns
fatal: Couldn't find remote ref xxx/yyy
Unexpected end of command stream
So I tried another way:
mkdir tmp
cd tmp
git init
git clone url_for_xxx.git yyy
And subtree add
from that temp rep's master branch:
git subtree add -P yyy /path/to/tmp/ master
来源:https://stackoverflow.com/questions/16829401/adding-git-subtree-from-a-branch