简体   繁体   English

使用 `git branch -a` 列出所有分支不显示最近获取的分支?

[英]List all branches with `git branch -a` does not show recently fetched branch?

I have this history in the console:我在控制台中有这段历史:

Resolving deltas: 100% (58156/58156), completed with 1585 local objects.
From bitbucket.org:interos/datavana
 * branch                datavana.dev.py.3.7.3 -> FETCH_HEAD

$ git checkout datavana.dev.py.3.7.3
error: pathspec 'datavana.dev.py.3.7.3' did not match any file(s) known to git

$ git branch
* alex/dockerize
  master

$ git branch -a
* alex/dockerize
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

I noticed a problem when I tried running:我在尝试运行时注意到一个问题:

git checkout datavana.dev.py.3.7.3

because as you can see that didn't work, and this branch is also not listed using git branch -a , anybody know why I can't checkout this branch?因为正如您所看到的那样没有用,而且这个分支也没有使用git branch -a列出,有人知道为什么我不能签出这个分支吗?

If you take a look the top of your question, you see: 如果您查看问题的顶部,则会看到:

* branch                datavana.dev.py.3.7.3 -> FETCH_HEAD

This means that the remote reference datavana.dev.py.3.7.3 has been stored locally in FETCH_HEAD . 这意味着远程引用datavana.dev.py.3.7.3已本地存储在FETCH_HEAD It did not create a local branch with the same name. 没有创建具有相同名称的本地分支。

You can create a local branch named datavana.dev.py.3.7.3 by running: 您可以通过运行以下datavana.dev.py.3.7.3 创建一个名为datavana.dev.py.3.7.3的本地分支:

git checkout -b datavana.dev.py.3.7.3 FETCH_HEAD

You probably ran git fetch <remote> datavana.dev.py.3.7.3 , in which case what you see is the expected behavior. 您可能运行了git fetch <remote> datavana.dev.py.3.7.3 ,在这种情况下,您看到的是预期的行为。 From the git-fetch man page: git-fetch手册页:

The names of refs that are fetched, together with the object names they point at, are written to .git/FETCH_HEAD. 获取的ref的名称以及它们指向的对象名称将写入.git / FETCH_HEAD。 This information may be used by scripts or other git commands, such as git-pull(1). 脚本或其他git命令(例如git-pull(1))可以使用此信息。

You would normally check out a remote branch using git checkout . 通常,您可以使用git checkout签出远程分支。

why did it do the FETCH_HEAD thing, never seen that before?为什么它会执行FETCH_HEAD操作,以前从未见过?
I just ran git fetch我刚刚运行了git fetch

Then double-check your git config remote.origin.fetch setting:然后仔细检查您的git config remote.origin.fetch设置:
A default refspec should have created the local branch for you on fetch:默认的 refspec应该已经在获取时为你创建了本地分支:

+refs/heads/*:refs/remotes/origin/*

But if you have a different refspec, then the remote branch is fetched, and its reference is stored in FETCH_HEAD但是如果你有一个不同的 refspec,那么远程分支被获取,它的引用存储在 FETCH_HEAD 中

A git fetch datavana.dev.py.3.7.3:datavana.dev.py.3.7.3 would also have created the branch locally. git fetch datavana.dev.py.3.7.3:datavana.dev.py.3.7.3也会在本地创建分支。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM