问题描述
我的两个办公室和家里的电脑让Git的Bash for Windows的非常相同的源(GIT适用于Windows,与TortoiseGit来了),但混帐击的提示不同,在两台机器上:
Both my office and home computers have Git Bash for Windows from the very same source (Git for Windows, that came with TortoiseGit), but Git Bash's prompt differs on both machines:
- 我
/ C /路(支)
全绿(这是,我怎么想它有), - 家用电脑上我唯一路径(没有分支)和全白。
办公室的电脑上
- on office computer I have
/c/path (branch)
all green (this is, how I would like it to have), - on home computer I have only path (no branch) and all white.
到现在为止,我被告知,这是 PS1
变量,保存在〜/ .bashrc中
文件。然而,在两台机器上,该文件丢失(执行记事本的〜/ .bashrc
打开记事本为空)。
Up until now I was told, that this is PS1
variable, kept in ~/.bashrc
file. However, on both machines, this files is missing (executing notepad ~/.bashrc
opens up empty Notepad).
我在这里丢失。如果〜/ .bashrc中
不存在,那么从那里的Git Bash的知道,它应该显示当前分支,在一个绿色的提示?而为什么同样没有第二台机器上发生的?
I'm lost here. If ~/.bashrc
doesn't exists, then from where Git Bash "knows", that it should display current branch, in a green prompt? And why the same doesn't happen on second machine?
修改:我也试过来比较 C:\\ Program Files文件\\的Git \\等\\
两台机器和内容文件夹的内容的的Git Bash.vbs
文件。有两台计算机上都是相同的,所以我更不知道,怎么会这样,那混帐击的提示不同的两台计算机上(以及如何解决这一问题)。的
EDIT: I also tried to compare c:\Program Files\Git\etc\
folder contents for both machines and contents of Git Bash.vbs
file. There identical on both computers so I even more have no idea, how it can be, that Git Bash's prompt differs on both computers (and how to fix this).
若干答案(如,的和)曾建议我,我应该寻找 .bash_profile中
和 .bash_prompt
文件。不幸的是,这两个还缺少我的两个计算机上。
Several answers (like this, this and this) has suggested me, that I should look for .bash_profile
and .bash_prompt
files. Unfortunately, these two also are missing on both my computers.
究竟是什么文件决定有关在Windows 7下?还有什么地方我应该寻找,什么 PS1
变量的值应该是,已显示出当前分支中的绿色提示在两台机器上?
Exactly what file decides about that under Windows 7? Where else should I look for, and what PS1
variable's value should be, to have current branch shown in green prompt on both machines?
推荐答案
混帐Windows上几乎总是使用bash shell的。所以,这不是混帐的设置提示的多达猛砸一样。
Git on Windows almost always uses a bash shell. So, it's not Git setting the prompt as much as Bash does.
有两种方法设置提示的猛砸。一个是 PS1
命令,它是相当灵活的,但被限制在一组特定的转义字符序列。遗憾的是,Git的信息是不是这些转义序列之一(虽然我怀疑它会来的一天)。您可以使用第二种方式通过设置 PROMPT_COMMAND
环境变量设置提示。如果这样设置,则 $ PROMPT_COMMAND
被执行,作为提示,而不是 PS1
环境变量。
There are two ways to set prompts in Bash. One is the PS1
command which is fairly flexible, but is limited to a particular set of escape character sequences. Unfortunately, Git information isn't one of those escape sequences (although I suspect it'll come someday). You can use the second way to set the prompt by setting the PROMPT_COMMAND
environment variable. If this is set, the $PROMPT_COMMAND
is executed and used as the prompt instead of the PS1
environment variable.
当您使用bash安装标准的Git,你的Git提示的 / etc / profile文件
文件下定义。顺便说一句,等
是你已经安装在Git的下一个目录通常是在%PROGRAMFILES%
除非你当你安装的Git改变了它。
When you install the standard Git with BASH, you're Git prompt is defined under the /etc/profile
file. By the way, etc
is a directory under where you've installed Git which is usually under %PROGRAMFILES%
unless you changed it when you installed Git.
在 / etc / profile文件
脚本线#156在我的版本,可以看到 PS1
命令是设置并使用 $(__ git_ps1)
在 $ PS1
在命令提示符下执行外部命令的手段。 (第三种方法我没有提到previously)。
Under the /etc/profile
script in line #156 in my version, you see the PS1
command being set and using $(__git_ps1)
in $PS1
as a means of executing an external command in the prompt. (A third way I didn't mention previously).
的 __ git_ps1
是一个外壳的功能。您还会注意到位以上(在我的版本线#154)的 /etc/git-completion.bash
中以及被作为源 /etc/git-prompt.sh
。这是 /etc/git-prompt.sh
定义 __ git_ps1
功能(Line在我的版本#273)的定义。你会发现,在 __ git_ps1
功能在 /etc/git-prompt.sh
定义了几个其他功能拉。
The __git_ps1
is a shell function. You'll also notice a bit above (line #154 in my version) that /etc/git-completion.bash
is being sourced in as well as /etc/git-prompt.sh
. It's /etc/git-prompt.sh
that defines the __git_ps1
function (Line #273 in my version) is defined. You'll notice that the __git_ps1
function pulls in several other functions defined in /etc/git-prompt.sh
.
所以,在一个非常鲁贝戈德堡方式,Git的提示正在 / etc / profile文件
通过定义 $ PS1 这拉在
功能分为 /etc/git-prompt.sh
定义,在一个拉 __ git_ps1
功能 __ git_ps1_show_upstream
函数和 __ git_ps1_colorize_gitstring
功能。然后, $ PS1
使用 $(...)
字符串作为 __ git_ps1 PS1
。
So, in a very Rube Goldberg manner, the Git prompt is being defined in /etc/profile
via defining $PS1
which pulls in /etc/git-prompt.sh
which defines a __git_ps1
function that pulls in the __git_ps1_show_upstream
function and the __git_ps1_colorize_gitstring
function. Then, $PS1
uses the $(...)
string as part of pulling in the __git_ps1
function into PS1
.
您可以定义自己的 $ HOME / .bash_profile中
覆盖提示设置来定义自己的提示方式。而且,当你这样做,你也可以使用 __ git_ps1
bash函数在自己的提示。
You can define your own $HOME/.bash_profile
to override the way the prompt is set to define your own prompt. And, when you do that, you can also use the __git_ps1
Bash function in your own prompt.
或者,你可以简单地决定不碰任何东西,只是往回走得很慢。毕竟,你可能有实际的工作要做。
Or, you can simply decide not to touch anything, and just back away very slowly. After all, you may have actual work to do.
这篇关于确切位置在哪里混帐击的Windows“的提示定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!