【问题标题】:'git branch' does not show the branches names'git branch' 不显示分支名称
【发布时间】:2018-06-12 18:38:47
【问题描述】:

我在 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并重新安装了它。它没有帮助)

知道怎么解决吗?

【问题讨论】:

  • 评论不用于扩展讨论;这个对话是moved to chat
  • 更新:我使用 git config --global pager.branch false 禁用了 git branch 的 git 寻呼机。现在我可以得到结果了。但正如@Keith 所说,我们仍然不知道为什么 pager 会导致这个问题。

标签: github git-branch


【解决方案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 是一种解决方法,所以问题一定是这样。

【讨论】:

    【解决方案2】:

    显示本地分支:

    git branch
    

    由于您是从远程/原始分支克隆,它不会使用 git 分支显示。您至少需要使用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?

    【讨论】:

    • 在这种情况下,OP 不是在创建新的存储库,而是在下载现有的存储库。
    • 我还仔细检查了以确保存储库不在任何其他存储库中。我也在另一个地方重新克隆了它。同样的事情
    • @A_sh 请查看上述步骤。
    • 请检查问题,我已经更新了@Nisarg
    • 谢谢@Nisarg。这是相同的。我这样做了。我也提交了一个文件,它仍然是一样的。请检查问题
    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-22
      • 2018-07-15
      • 2012-02-04
      • 2016-06-14
      • 2012-09-01
      • 2018-11-18
      • 2019-12-25
      • 2020-04-12
      相关资源
      最近更新 更多