Isa*_*man 2 git git-checkout git-remote
我正在做一个有两个遥控器的项目,一个叫origin,另一个叫vsts。默认的遥控器是origin。这是的输出git remote -v,其中一些部分匿名表示为***:
$ git remote -v
origin git@bitbucket.org:***/***.git (fetch)
origin git@bitbucket.org:***/***.git (push)
vsts ssh://***@vs-ssh.visualstudio.com:***/DefaultCollection/***/_ssh/*** (fetch)
vsts ssh://***@vs-ssh.visualstudio.com:***/DefaultCollection/***/_ssh/*** (push)
我正尝试从中签出新的分支vsts。叫做release/1.4.1。我在Git 2.16.x上,因此我应该可以使用git checkout,但这是发生的情况:
$ git checkout release/1.4.1
error: pathspec 'release/1.4.1' did not match any file(s) known to git.
我想也许是我的意思origin。所以我尝试这样:
$ git checkout vsts/release/1.4.1
error: pathspec 'vsts/release/1.4.1' did not match any file(s) known to git.
我应该确保git可以找到分支。所以我git ls-remote用来获取远程分支的列表:
$ git ls-remote vsts
...
abcde*** refs/heads/release/1.4.1
...
我得到了分支和提交哈希的列表,并且release/1.4.1绝对是其中之一。
我再尝试几件事:
$ git checkout -b release/1.4.1 vsts/release/1.4.1
fatal: 'vsts/release/1.4.1' is not a commit and a branch 'release/1.4.1' cannot be created from it
$ git fetch vsts release/1.4.1
From ssh://vs-ssh.visualstudio.com:***/DefaultCollection/***/_ssh/***
* branch release/1.4.1 -> FETCH_HEAD
(执行此命令后,我将再次尝试所有先前的命令。结果保持不变。)
$ git checkout -b release/1.4.1 remotes/vsts/release/1.4.1
fatal: 'remotes/vsts/release/1.4.1' is not a commit and a branch 'release/1.4.1' cannot be created from it
$ git checkout -b release/1.4.1 remotes/vsts/refs/heads/release/1.4.1
fatal: 'remotes/vsts/refs/heads/release/1.4.1' is not a commit and a branch 'release/1.4.1' cannot be created from it
如果我尝试git pull vsts/release/1.4.1将远程分支成功合并release/1.4.1到当前分支,但这不是一个有用的解决方法。
我还能尝试什么?我不明白为什么我不能签出远程分支。
问题是我的本地git配置被搞砸了。我曾经git config --local -e在vim中打开它,然后发现了这一部分:
[remote "vsts"]
url = ssh://***@vs-ssh.visualstudio.com:***/DefaultCollection/***/_ssh/***
fetch = +refs/heads/dev:refs/remotes/vsts/dev
看起来只是设置为fetch dev。我不知道它是怎么实现的,但是我将其更改为以下内容:
[remote "vsts"]
url = ssh://***@vs-ssh.visualstudio.com:***/DefaultCollection/***/_ssh/***
fetch = +refs/heads/*:refs/remotes/vsts/*
之后,我可以执行以下操作:
$ git checkout release/1.4.1
Switched to a new branch 'release/1.4.1'
Branch 'release/1.4.1' set up to track remote branch 'release/1.4.1' from 'vsts'.