'git branch'不显示分支名称

时间:2018-06-12 18:38:47

标签: github git-branch

我在ubuntu上使用git。

git branch未显示分支的名称。我尝试克隆不同的存储库,但git branch再次没有显示分支的名称。 我还创建了一个新的存储库,它是一样的。

示例:

>git clone https://github.com/uber/pyro.git
Cloning into 'pyro'...
remote: Counting objects: 13342, done.
remote: Compressing objects: 100% (23/23), done.
remote: Total 13342 (delta 8), reused 0 (delta 0), pack-reused 13319
Receiving objects: 100% (13342/13342), 55.85 MiB | 5.34 MiB/s, done.
Resolving deltas: 100% (9814/9814), done.
>ls
pyro
>cd pyro
>git branch -a
>git branch -r
>git branch
>git status
On branch dev
Your branch is up to date with 'origin/dev'.

添加另一个分支:

>git checkout -b branch1
Switched to a new branch 'branch1'
>git branch
>

我也承诺了一次。它是一样的。

>GIT_TRACE=1 git branch
15:39:13.295464 git.c:344               trace: built-in: git branch
15:39:13.296121 run-command.c:640       trace: run_command: unset 
GIT_PAGER_IN_USE; LESS=FRX LV=-c pager
>git --version
git version 2.17.1
>
>env -i git branch
WARNING: terminal is not fully functional
* devress RETURN)
>

我在另一台笔记本电脑上测试过相同的命令,但它确实有效。 (我也卸载了git并重新安装它。它没有帮助)

知道怎么解决吗?

3 个答案:

答案 0 :(得分:1)

这不是一个完整的答案,但基于冗长的聊天讨论,它看起来像是与寻呼机的某种互动。

用户的环境包括这些变量(以及其他):

LESSOPEN='| /usr/bin/lesspipe %s'
LESSCLOSE='/usr/bin/lesspipe %s %s'

这些是Ubuntu上的默认设置,因此不应该导致问题。

git branch不产生任何输出。

GIT_PAGER=/bin/cat git branch生成正确的输出。

我还没有弄清楚为什么寻呼机应该导致此问题,但由于将GIT_PAGER更改为/bin/cat是一种解决方法,因此必须解决问题。

答案 1 :(得分:0)

显示本地分支机构:

git branch

由于您是从远程/原始分支克隆的,因此不会使用git branch进行显示。您需要使用git checkout至少访问该分支。查看下面的git命令。我创建了新分支hotfix-test,然后使用了git branch

~/pyro (dev)

    $ git checkout -b hotfix-test
    Switched to a new branch 'hotfix-test'

~/pyro (hotfix-test)

    $ git branch
      dev
    * hotfix-test

检查当前分支到现有的其他分支。

$ git checkout lax
Switched to a new branch 'lax'
Branch lax set up to track remote branch lax from origin.

~/pyro (lax)
 $ git branch
          dev
          hotfix-test
        * lax

克隆步骤和原始分支

 ~/desktop (master)
$ git clone https://github.com/uber/pyro.git
Cloning into 'pyro'...
remote: Counting objects: 13342, done.
remote: Compressing objects: 100% (23/23), done.
remote: Total 13342 (delta 8), reused 0 (delta 0), pack-reused 13319
Receiving objects: 100% (13342/13342), 55.85 MiB | 2.69 MiB/s, done.
Resolving deltas: 100% (9814/9814), done.

~/desktop (master)
$ cd pyro

desktop/pyro (dev)
$ git branch -a
* dev
  remotes/origin/0.1.2-release
  remotes/origin/0.2.0-release
  remotes/origin/0.2.1-release
  remotes/origin/HEAD -> origin/dev
  remotes/origin/ast-char-rnn
  remotes/origin/bnn-mnist
  remotes/origin/causal-tutorial
  remotes/origin/continuation-poutine
  remotes/origin/continuation-with-indep
  remotes/origin/cubo
  remotes/origin/dev
  remotes/origin/dice-elbo
  remotes/origin/gh-pages
  remotes/origin/glom-autoname
  remotes/origin/hmc
  remotes/origin/jit-integration-tests
  remotes/origin/lax
  remotes/origin/lax2
  remotes/origin/maps-iei
  remotes/origin/master
  remotes/origin/mvn-sym
  remotes/origin/mvncv
  remotes/origin/nightmare-poutine
  remotes/origin/nips-2017
  remotes/origin/only-continuation-poutine
  remotes/origin/only-parallel-enumeration
  remotes/origin/paul-mh-12-1
  remotes/origin/pcg
  remotes/origin/pragmatics-example
  remotes/origin/ps-semaphore
  remotes/origin/pyro_GP
  remotes/origin/recursion-scope
  remotes/origin/regtest-1
  remotes/origin/rejector-research
  remotes/origin/revert-611-verlet-pr
  remotes/origin/rsa-ccg-example
  remotes/origin/sampling-hash
  remotes/origin/snorkel-example
  remotes/origin/trace-posterior-sample-fix
  remotes/origin/tst
  remotes/origin/vec-rand-module

 ~/desktop/pyro (dev)
$ git branch -r
  origin/0.1.2-release
  origin/0.2.0-release
  origin/0.2.1-release
  origin/HEAD -> origin/dev
  origin/ast-char-rnn
  origin/bnn-mnist
  origin/causal-tutorial
  origin/continuation-poutine
  origin/continuation-with-indep
  origin/cubo
  origin/dev
  origin/dice-elbo
  origin/gh-pages
  origin/glom-autoname
  origin/hmc
  origin/jit-integration-tests
  origin/lax
  origin/lax2
  origin/maps-iei
  origin/master
  origin/mvn-sym
  origin/mvncv
  origin/nightmare-poutine
  origin/nips-2017
  origin/only-continuation-poutine
  origin/only-parallel-enumeration
  origin/paul-mh-12-1
  origin/pcg
  origin/pragmatics-example
  origin/ps-semaphore
  origin/pyro_GP
  origin/recursion-scope
  origin/regtest-1
  origin/rejector-research
  origin/revert-611-verlet-pr
  origin/rsa-ccg-example
  origin/sampling-hash
  origin/snorkel-example
  origin/trace-posterior-sample-fix
  origin/tst
  origin/vec-rand-module

另见 Why is "git branch" silent in new repositories?

答案 2 :(得分:0)

我已使用git branch停用了git config --global pager.branch false的git寻呼机。现在我可以获得git branch输出。但我们并没有弄清楚寻呼机问题是什么。对于git diff等其他命令,存在同样的问题。