为什么 Git 不让我从另一个远程检查分支?
Why won't Git let me check out a branch from an alternate 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
看起来它只设置为获取 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'.
我正在做一个有两个遥控器的项目,一个叫 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
看起来它只设置为获取 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'.