为什么不让Git让我从备用遥控器上查看一个分支?

时间:2018-04-03 17:08:06

标签: 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合并到当前分支中,但这不是一个有用的解决方法。

我还能尝试什么?我不明白为什么我无法查看远程分支。

1 个答案:

答案 0 :(得分:5)

问题是我的本地git配置搞砸了。我使用git config --local -e在vim中打开它,找到了这一部分:

[remote "vsts"] url = ssh://***@vs-ssh.visualstudio.com:***/DefaultCollection/***/_ssh/*** fetch = +refs/heads/dev:refs/remotes/vsts/dev

看起来它只设置为获取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'.

相关问题