为什么我需要root特权才能执行`git branch -a`? [英] Why do I need Root privilege to do `git branch -a`?

查看:161
本文介绍了为什么我需要root特权才能执行`git branch -a`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

git存储库位于我的用户名nikhil和组nikhil下,如下所示:

The git repository is under my username nikhil and group nikhil as follows:

$ ls -l
drwxr-xr-x 10 nikhil nikhil 4096 Sep  1 12:33 CS/

我无需root特权即可获得git status的git状态.

I can get git status as git status without root privilege.

但是当我尝试列出分支机构时:

But when I try to list branches:

$  git branch -a

什么都没发生.

还具有root特权:

$ sudo git branch -a
[sudo] password for nikhil:
* master
  remotes/origin/feature
  remotes/origin/master

它确实列出了我所有的存储库.

it does lists all my repository.

为什么会这样?

ls -lh .git

$ ls -lh .git
total 332K
drwxr-xr-x   2 nikhil nikhil 4.0K May 25 16:32 branches
-rw-r--r--   1 nikhil nikhil    2 Sep  1 12:25 COMMIT_EDITMSG
-rw-r--r--   1 nikhil nikhil 5.6K Sep  1 12:33 config
-rw-r--r--   1 nikhil nikhil   73 May 25 16:32 description
-rw-r--r--   1 nikhil nikhil   90 Sep  1 12:33 FETCH_HEAD
-rw-rw-r--   1 nikhil nikhil   23 Sep  1 12:33 HEAD
drwxr-xr-x   2 nikhil nikhil 4.0K Jun 11 15:25 hooks
-rw-r--r--   1 nikhil nikhil 229K Sep  1 12:34 index
-rw-r--r--   1 nikhil nikhil  44K Jun 11 08:56 INDEX
drwxr-xr-x   2 nikhil nikhil 4.0K Jun 11 15:25 info
drwxr-xr-x   3 nikhil nikhil 4.0K Jun 11 15:28 logs
drwxr-xr-x   8 nikhil nikhil 4.0K Aug 11 18:01 modules
drwxr-xr-x 260 nikhil nikhil 4.0K Jun 27 15:29 objects
-rw-rw-r--   1 nikhil nikhil   41 Sep  1 12:33 ORIG_HEAD
drwxr-xr-x   5 nikhil nikhil 4.0K Jun 11 15:25 refs


我在.bashrc中确定了由于Anaconda造成的问题:


I identified the problem it was due to Anaconda in my .bashrc:

export PATH="$HOME/anaconda3/bin:$PATH"
if [ -f $HOME/anaconda3/etc/profile.d/conda.sh ]; then
    source $HOME/anaconda3/etc/profile.d/conda.sh
fi
conda activate

我该怎么办?当我对此发表评论时,git branch -a可行.

What should I do? When I comment this out git branch -a works.

推荐答案

conda提供了自己的pager二进制文件(不是moreless,而是pager).使用sudo会清除您的PATH,因此它不是通过更改权限来解决问题的,而是通过完全防止使用该错误的二进制文件来解决此问题.

conda provides its own pager binary (not more or less, but pager). Using sudo clears your PATH -- so it fixes the problem not by virtue of changing permissions, but by virtue of preventing this faulty binary from being used at all.

为防止此行为引起任何不良行为,请将其移开:

To prevent this from having any undesired behaviors, move it out of the way:

mv ~/anaconda3/bin/pager{,.bad}

这篇关于为什么我需要root特权才能执行`git branch -a`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆