git - 为什么 Git 不允许我从备用远程查看分支?

标签 git git-checkout git-remote

我正在开发一个有两个 Remote 的项目,其中一个名为 origin一个叫 vsts 。默认 Remote 为origin 。这是 git remote -v 的输出,其中一些部分匿名为 *** :

$ git remote -v origin <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="44232d3004262d302631272f21306a2b3623" rel="noreferrer noopener nofollow">[email protected]</a>:***/***.git (fetch) origin <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0e69677a4e6c677a6c7b6d656b7a20617c69" rel="noreferrer noopener nofollow">[email protected]</a>:***/***.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它成功 merge 远程分支 release/1.4.1进入当前分支,但这不是一个有用的解决方法。

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

最佳答案

问题是我的本地 git 配置搞砸了。我使用 git config --local -e 在 vi​​m 中打开它并找到了此部分:

[远程“vsts”] url = ssh://***@vs-ssh.visualstudio.com:***/DefaultCollection/***/_ssh/*** fetch = +refs/heads/dev:refs/remotes/vsts/dev

看起来它只是设置为获取dev。我不知道它是怎么变成这样的,但我将其更改为以下内容:

[远程“vsts”] url = ssh://***@vs-ssh.visualstudio.com:***/DefaultCollection/***/_ssh/*** fetch = +refs/heads/*:refs/remotes/vsts/*

之后我就可以执行以下操作:

$ git checkout 版本/1.4.1 切换到新分支“release/1.4.1” 分支“release/1.4.1”设置为跟踪“vsts”中的远程分支“release/1.4.1”。

关于git - 为什么 Git 不允许我从备用远程查看分支?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49635617/

相关文章:

git - pip 从 gitosis 安装

Git checkout 不会改变任何东西

github - 错误: Undo last git commit on both local and remote

Git 工作流 : Share code between computers without pushing to public repo

git-svn 和不幸的 svn 预提交钩子(Hook)

Git checkout : updating paths is incompatible with switching branches

git - 如何在 Git 中 check out 远程分支?

GIT:如何正确地将远程分支下载到本地?

windows - 如何编辑我的 .git/config 文件?

git - 在 git 中重命名 Remote 是否安全?