Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git &引用;无法同时更新路径和切换到分支";_Git_Git Checkout - Fatal编程技术网

Git &引用;无法同时更新路径和切换到分支";

Git &引用;无法同时更新路径和切换到分支";,git,git-checkout,Git,Git Checkout,我有时使用checkout-b选项创建一个新分支,同时将其签出,并在一个命令中设置跟踪 在新环境中,我遇到以下错误: $ git checkout -b test --track origin/master fatal: Cannot update paths and switch to branch 'test' at the same time. Did you intend to checkout 'origin/master' which can not be resolved as c

我有时使用
checkout-b
选项创建一个新分支,同时将其签出,并在一个命令中设置跟踪

在新环境中,我遇到以下错误:

$ git checkout -b test --track origin/master
fatal: Cannot update paths and switch to branch 'test' at the same time.
Did you intend to checkout 'origin/master' which can not be resolved as commit?
为什么Git不喜欢它?这一点过去也适用于同一回购协议

无法解析为提交的“
origin/master

奇怪:你需要检查你的遥控器:

git remote -v
并确保已提取
原点

git fetch origin
然后:

(查看您是否已获取
源代码/主代码
分支)

最后,使用Git 2.23+(2019年8月)代替


如果您的branchname中有一个输入错误,您将得到相同的错误。

您可以在Travis构建的上下文中得到此错误,例如,默认情况下,Travis构建使用git clone--depth=50--branch=master签出代码。据我所知,您可以通过
.travis.yml
控制
--depth
,但不能控制
--branch
。由于这只会导致远程设备跟踪单个分支,因此需要独立更新远程设备以跟踪所需远程设备的引用

之前:

$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
修复方法:

$ git remote set-branches --add origin branch-1
$ git remote set-branches --add origin branch-2
$ git fetch
之后:

$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/branch-1
remotes/origin/branch-2
remotes/origin/master

这件简单的事对我很管用

如果它说不能同时做两件事,就把它们分开

git branch branch_name origin/branch_name 

git checkout branch_name

对我来说,我需要添加遥控器:

git remote -add myRemoteName('origin' in your case) remoteGitURL
然后我可以去拿

git fetch myRemoteName

首先,您需要
获取
远程(特定分支),然后您可以创建一个本地br,并使用您的命令(即
签出
,使用-b和--track)跟踪该远程分支。

遇到此问题时,您可以按照以下步骤操作:

  • 运行以下命令列出本地存储库已知的分支
  • git远程显示源代码

    哪个输出:

    如您所见,新分支已从远程获取
    3.最后,使用此命令签出分支

    不必显式地告诉Git跟踪(使用--track)远程跟踪的分支


    上述命令将本地分支设置为从原点跟踪远程分支。

    您应该转到子模块dir并运行
    git status

    您可能会看到许多文件被删除。你可以跑

  • git重置。

  • git签出。

  • git fetch-p

  • git-rm——缓存的子模块
    //子模块是您的名字

  • git子模块添加…


  • 您可以使用以下命令: git远程更新, git fetch, git签出-b分支机构名称A来源:分支机构名称b


    我想可能是因为您的本地分支无法跟踪远程分支

    这是因为您的本地分支无法跟踪远程分支。 正如ssasi所说,您需要使用以下命令:

    git remote update
    git fetch
    git checkout -b branch_nameA origin/branch_nameB
    

    我刚刚解决了我的问题….

    如果您的分支中有空白,则会出现此错误。

    在我的情况下,我必须使用以下命令使用远程存储库中的最新标记更新我的locate git存储库:

    git fetch --tags
    
    获取远程存储库标记的命令可能因组织的Git设置而异


    执行此操作后,
    git checkout
    工作。

    错误消息告诉您
    origin/master
    不是提交ID,即不是有效的远程分支。它是否显示在git branch-r输出中?它没有。原来我在克隆过程中没有签出所有远程分支。我的命令中有一个输入错误触发了此错误;我的遥控器拼错了!这是一个新的分支,我的本地存储库不知道它。我必须做一个
    ,然后这个命令就起作用了。这个答案很有帮助,因为它告诉我确实发生了一些奇怪的事情:远程设置正确,但新的远程分支根本没有被提取。当我在一个干净的目录中克隆远程设备时,它可以工作。我的
    .git
    目录是否可能以某种方式损坏?git remote-v返回了一个致命错误:不是有效的对象名:“remote”。@KarimSamir您可以问一个单独的问题(对于您的操作系统和git版本),由于在git repo中执行的
    git remote-v
    确实有效。事实上,如果有人能抽出时间告诉git开发人员这一点,那就太好了,错误消息的信息量不大;)是的,这是我的问题,我的分支名称中有一个空格,我尝试
    git checkout-b origin mybranch
    而不是
    git checkout-b mybranch
    (额外
    origin
    )我复制粘贴了我的分支名称,导致此错误的分支名称后有尾随空格。我试图签出
    orgin/my branch
    ,而不是
    origin/my branch
    。错过了一个我&我一直在挠头,想弄明白为什么一个老盟友拒绝和睦相处。错别字确实是个问题,帮我解决了。我使用了一个浅的--depth=1克隆,这就是我切换分支所需要的。是的,深度肯定会导致这个错误!如果可能的话,我建议对前几句话进行编辑,以强调深度。这样可以很容易地找出真正的问题是什么
     remote origin
      Fetch URL: <your_git_path>
      Push  URL: <your_git_path>
      HEAD branch: development
      Remote branches:
        development                             tracked
        Feature2                                tracked
        master                                  tracked
        refs/remotes/origin/Feature1         stale (use 'git remote prune' to remove)
      Local branches configured for 'git pull':
        Feature2     merges with remote Feature2
        development  merges with remote development
        master       merges with remote master
      Local refs configured for 'git push':
        Feature2     pushes to Feature2     (up to date)
        development  pushes to development (up to date)
        master       pushes to master      (local out of date)
    
    » git remote update
    
    Fetching origin
    From gitlab.domain.local:ProjectGroupName/ProjectName
     * [new branch]      Feature3    -> Feature3
    
    » git checkout -b Feature3 origin/Feature3
    
    Branch Feature3 set up to track remote branch Feature3 from origin.
    Switched to a new branch 'Feature3'
    
    git remote update
    git fetch
    git checkout -b branch_nameA origin/branch_nameB
    
    git fetch --tags