bash 我的 shell 提示符如下所示:〜git:(大师)?。我怎样才能恢复正常的提示?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25351213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 11:10:10  来源:igfitidea点击:

My shell prompt looks like this: ? ~ git:(master) ?. How can I get my normal prompt back?

gitbashterminalgit-svn

提问by Programmer345

My normal terminal command line has suddenly disappeared and has been replaced by this git command line ? ~ git:(master) ?.

我正常的终端命令行突然消失了,被这个git命令行代替了? ~ git:(master) ?

How do I get rid of this and go back to my normal command line in Terminal? I on Mac OS X.

我如何摆脱这个并回到我在终端中的正常命令行?我在 Mac OS X 上。

I have tried typing exit, Ctrl+c, q, etc. but nothing helped.

我曾尝试打字exitCtrl+ cq等,但没有任何帮助。

回答by jub0bs

You must have installed something (I'm not sure what) that modified your prompt to give you context-sensitive information about the Git repository (if any) you're in.

您必须安装了一些东西(我不确定是什么)修改了您的提示,以便为您提供有关您所在的 Git 存储库(如果有)的上下文相关信息。

Simply adding

简单地添加

export PS1="\h:\W \u$ "

at the very bottom of your

在你的最底层

  • ~/.bash_profilefile, if you use bash, or
  • ~/.zshrcfile, if you use zsh,
  • ~/.bash_profile文件,如果您使用bash, 或
  • ~/.zshrc文件,如果你使用zsh

and then sourcing that file (or restarting Terminal) should rid you of that fancy colourful prompt.

然后获取该文件(或重新启动终端)应该让您摆脱那个花哨的彩色提示。

回答by frank.lin

I know your problem , You are using zsh, right?

我知道你的问题,你正在使用zsh,对吗?

If so, you should add export PS1=xxxxxto ~/.zshrc, not ~/.bashrc.

如果是这样,您应该添加export PS1=xxxxx~/.zshrc,而不是~/.bashrc

Or you just don't use zsh, input bashand switch to bash.inputchsh -s /bin/bashto change the default shell to bash.

或者您只是不使用zsh, inputbash和 switch tobash.inputchsh -s /bin/bash将默认 shell 更改为bash.

回答by A. Mandel

This happened to me when getting my head around zsh and git. I created a git repo in the wrong folder and started seeing this zsh context. Because I didn't want a repo in this directory I removed the git information with:

当我了解 zsh 和 git 时,这发生在我身上。我在错误的文件夹中创建了一个 git repo 并开始看到这个 zsh 上下文。因为我不想在这个目录中有一个 repo,所以我删除了 git 信息:

rm -R .git

rm -R .git

Note you will only want to do this if you have an invalid git repository.

请注意,如果您的 git 存储库无效,您只会想要这样做。

回答by Shubo Wang

There is nothing wrong with your system or you change something involuntarily. You must have download oh-my-zsh and set your default terminal from bash to zsh. Oh-my-zsh has many different themes, all these themes have different appearances and provide more efficient functions, git information is one of them. The default theme of oh-my-zsh is "robbyrussell" and it just looks like your shell prompt. You can go to "~/.oh-my-zsh/themes" to choose your favorite theme and apply it to the configuration file "./zshrc". I know you have solved the problem by uninstalled the zsh and use the original bash, I just want to tell you the essential reason of this problem. And oh-my-zsh truly provides some convenience which helps you use the command line, maybe you should try it again!

你的系统没有任何问题,或者你不由自主地改变了一些东西。您必须下载 oh-my-zsh 并将默认终端从 bash 设置为 zsh。Oh-my-zsh 有很多不同的主题,所有这些主题都有不同的外观并提供更高效的功能,git 信息就是其中之一。oh-my-zsh 的默认主题是“robbyrussell”,它看起来就像你的 shell 提示符。您可以到“~/.oh-my-zsh/themes”中选择您喜欢的主题并将其应用到配置文件“./zshrc”中。我知道你已经通过卸载zsh并使用原始bash解决了问题,我只想告诉你这个问题的本质原因。而且 oh-my-zsh 确实提供了一些方便,可以帮助您使用命令行,也许您应该再试一次!

回答by ShalomGideon

I also has this problem like: "? ~ git:(master) ?" on the Mac OS X. Because I type the command "git init".

我也有这样的问题:“?~ git:(master) ?” 在 Mac OS X 上。因为我输入了命令“git init”。

When I type the command "rm -R .git", it comes back into normal command line in Terminal. PS: I use zsh.

当我输入命令“rm -R .git”时,它会回到终端中的正常命令行。PS:我使用 zsh。

回答by Andrew Iseman

I'm assuming you entered "git init" like I did. It took me a while to figure this out, but when you entered "git init" you created a hidden git folder named ".git".

我假设您像我一样输入了“git init”。我花了一段时间才弄清楚这一点,但是当您输入“git init”时,您创建了一个名为“.git”的隐藏 git 文件夹。

You can see the folder by going to your home directory and typing "ls -a".

您可以通过转到您的主目录并键入“ls -a”来查看该文件夹。

Simply remove the file (rm -rf .git), and the prompt will magically disappear.

只需删除文件(rm -rf .git),提示就会神奇地消失。

回答by vignesh karnika

Open your ZSH config file

打开您的 ZSH 配置文件

sudo vim ~/.zshrc

须藤vim ~/.zshrc

and paste below command at the bottom of the file

并将下面的命令粘贴到文件底部

PROMPT='${ret_status} %{$fg[cyan]%}%c%{$reset_color%} '

PROMPT='${ret_status} %{$fg[青色]%}%c%{$reset_color%} '

this will show current directory

这将显示当前目录

回答by zblunt

Just ran into this problem. Sharing how I resolved for my future self.

刚遇到这个问题。分享我如何为未来的自己解决问题。

When switching to zsh in home/username, the shell shows git:(master). This is due to 2 things: 1. You have installed a Git package for ZSH 2. You have likely created a .git repo under home/username so zsh is picking it up from your current location.

在 home/username 中切换到 zsh 时,shell 显示 git:(master)。这是由于 2 件事: 1. 您已经为 ZSH 安装了一个 Git 包 2. 您可能已经在 home/username 下创建了一个 .git repo,因此 zsh 正在从您当前的位置获取它。

Steps to resolve: 1. Type ls -ainto terminal and you will be able to see .git and .gitconfig files 2. Move .git and .gitconfig files to your specified git repository folder with mv .git ./git_repositories/and mv .gitconfig ./git_repositories/3. type bashinto terminal then type zshinto terminal and it should resolve the issue.

步骤来解决:1.输入ls -a到终端,你将能够看到的.git和文件的.gitconfig 2.移动git的和的.gitconfig文件与您指定的Git存储库文件夹mv .git ./git_repositories/,并mv .gitconfig ./git_repositories/键入bash到终端,然后键入zsh到终端,它应该可以解决问题。

回答by aesede

There seems to be a few command line tools that work together with Git that add those customizations.

似乎有一些命令行工具可以与 Git 一起使用来添加这些自定义。

In my case after installing DrushI got my ~/.bashrcfile updated with Drush-specific customizations, which in this case addded a green (master *) $to the prompt, no matter where I was (veryannoying).

就我而言,在安装Drush 后,~/.bashrc使用 Drush 特定的自定义更新了我的文件,在这种情况下(master *) $,无论我身在何处,都会在提示中添加绿色(非常烦人)。

Fixed it by commenting out the block after # Include Drush prompt customizations.in my ~/.bashrcand then source ~/.bashrc

通过# Include Drush prompt customizations.在 my~/.bashrc和 then之后注释掉块来修复它source ~/.bashrc

回答by brian van vlymen

if you having seen the (master) in somewhere your folder. try this

如果您在文件夹的某个地方看到了(主人)。尝试这个

git rm .git

It will automatically remove the master

它会自动移除master