改变在Windows上的Git提示 [英] Alter Git prompt on Windows

查看:119
本文介绍了改变在Windows上的Git提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Git在Windows上,通过GitExtensions安装MSysGit(最新)在选择不修改我的Windows提示安装过程中。

I'm using Git on Windows, installed through GitExtensions with MSysGit (latest) having selected "do not modify my Windows prompt" during installation.

现在,我希望能够修改默认提示(默认情况下却与此分支名也给我多少时间,多少本地提交,因为我最后一次推送到起源(或专产地/主较容易)。

Now, I would like to be able to modify the default prompt (which by default shows just the branch name to also show me how much time, and how many local commits since I last pushed to origin (or specifically origin/master, whichever is easier).

所以说,而不是:我@ MYPC / C / myRepo(主)

我会看到线沿线的东西:我@ MYPC / C / myRepo(主)5 | 10:20

I would see something along the lines of: me@myPC /c/myRepo (master) 5 | 10:20

这意味着我还有最后推10小时20分钟前,因为我已经取得5本地提交。

meaning I have last pushed 10h 20min ago and I have made 5 local commits since.

在你提到它,我知道有使用PowerShell做这件事的方式,但我不希望使用它。我希望我的标准的Git的bash我们都知道和喜爱。

Before you mention it, I am aware there are ways of doing it with PowerShell, but I don't want to use it. I want my standard git bash we all know and love.

我发现那几个解决方案,并在的.bashrc 文件中修改 PS1 变量,但是(请原谅我可怜的Unix konwledge),他们似乎不工作,(例如接受的答案,<一个href=\"http://stackoverflow.com/questions/6883760/git-for-windows-bashrc-or-equivalent-config-files-for-git-bash-shell\">this问题)。

I found a few solutions to that, with modifying PS1 variable in .bashrc file, but (excuse my poor Unix konwledge) they seem to be not working, (for example accepted answer to this question).

所以你有它。这可能吗?

So there you have it. Is this possible?

推荐答案

默认的git-完成脚本支持你所追求的一部分。如果您在/ etc / profile文件中设置GIT_PS1_SHOWUPSTREAM =混帐冗长,那么它​​将增加数提前提交你的上游分支进入提示。您可能需要设置提示如下,以包括(%S)在GIT特定部分:

The default git-completion script supports part of what you are after. If you set GIT_PS1_SHOWUPSTREAM="verbose git" in the /etc/profile file then it will add the number of commits ahead of your upstream branch into the prompt. You may need to set the prompt as below to include a (%s) in the git specific part:

export PS1='\[\033]0;$MSYSTEM:\w\007
\033[32m\]\u@\h \[\033[33m\w$(__git_ps1 " (%s)")\033[0m\]
\$ '

有关部分时间 - 这就是新的我。但混帐bash中应如何处理,你可能已经发现任何UNIX版本。只需编辑/ etc / profile文件以管理员身份(其实际上%PROGRAMFILES%\\的Git \\等\\简介或创建一个包含〜/ .profile文件如下:

For the time part - thats new to me. But the git-bash should handle any unix version you may have found. Just edit /etc/profile as administrator (its actually %PROGRAMFILES%\Git\etc\profile or create a ~/.profile file containing the following:

GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWUPSTREAM='verbose git'
export GIT_PS1_SHOWDIRTYSTATE GIT_PS1_SHOWUPSTREAM

这些环境变量设置,默认msysGit这样的提示的外观,如果你有一个肮脏的树1提前提交原产地:

with these environment variables set, the default msysGit prompt looks like this if you have a dirty tree with 1 commit ahead of origin:

pat@FROG /c/src/msysgit (devel * u+1)
$ git status --short --branch
## devel...origin/devel [ahead 1]
 M doc/git/html
 M etc/inputrc

这篇关于改变在Windows上的Git提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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