在我的bash提示符,$(__ git_ps1)告诉我什么是错的,但什么? [英] In my bash prompt, $(__git_ps1) is telling me something is wrong, but what?

查看:167
本文介绍了在我的bash提示符,$(__ git_ps1)告诉我什么是错的,但什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我砍死我的bash提示(理论上)告诉我,目前我在什么混帐分支,但输出指示有点儿不对劲:

I've hacked my bash prompt to (in theory) tell me what git branch I'm currently in. But the output indicates that something's wrong:

22:07 (seesaw|REBASE-i) infwb $git branch
* master
  wkg

下面是我的.bash_profile文件中的相关code(我就会把它的一个更大的chunck在这个问题的末尾):

Here's the relevant code in my .bash_profile file (I'll put a larger chunck of it at the end of this question):

PS1="$GRAY\$(date +%H:%M)\$(__git_ps1) $GREEN\W$YELLOW \$"

正如你所看到的, $(__ git_ps1)收益(跷跷板| REBASE-I),即使我不再有跷跷板分支! (我也有一个,它在关系的重订问题我的远程分支跷跷板github上,我解决了这个问题,我想,和 git的分支-r跷跷板成功删除本地副本。)

As you can see, $(__git_ps1) returns (seesaw|REBASE-i), even though I no longer have a seesaw branch! (I did have one, and it had a rebase problem in relation to my remote seesaw branch on github. I solved the problem, I think, and git branch -r seesaw successfully removed the local copy.)

我是pretty确保(跷跷板| REBASE-I)是告诉我,什么是错的,但我不知道它是什么。

I'm pretty sure that (seesaw|REBASE-i) is telling me that something is wrong, but I don't know what it is.

感谢您的任何建议。 (.bash_profile中的如下块)

Thanks for any suggestions you might have. (chunk of .bash_profile follows)

-------from .bash_profile ---------

## ----- from http://en.newinstance.it/2010/05/23/git-autocompletion-and-enhanced-bash-prompt/
# Set git autocompletion and PS1 integration
if [ -f /usr/local/git/contrib/completion/git-completion.bash ]; then
  . /usr/local/git/contrib/completion/git-completion.bash
fi

if [ -f /opt/local/etc/bash_completion ]; then
    . /opt/local/etc/bash_completion
fi
## ----- end 

GRAY="\[\033[1;30m\]"
YELLOW="\[\033[1;33m\]"
GREEN="\[\033[0;32m\]"

PS1="$GRAY\$(date +%H:%M)\$(__git_ps1) $GREEN\W$YELLOW \$"

----------------

附录

@cdhowie和@manojlds,我对你们的git知识pssed IM $ P $!

@cdhowie and @manojlds, I'm impressed by your git knowledge!

git的变基--abort 导致信息更改为(跷跷板)。不幸的是,我无法找到变基合并(或的.git )的任何地方我的硬盘。我是Mac,这不奇怪的事情了许多开放源码软件的工具上。 (我没有找到自己的git,位于/ usr /本地/ GIT中)在/库/应用程序支持或〜//库/ Application Support没什么,无论是。

git rebase --abort caused the info to change to (seesaw). Unfortunately, I can't find rebase-merge (or .git) anywhere on my hard disk. I'm on a Mac, which does Weird Things to many FOSS tools. (I did find git itself, at /usr/local/git.) Nothing at /Library/Application Support or ~//Library/Application Support, either.

(再后来)

原来,一切都很好。不知怎的, git的变基--abort 引起跷跷板分支重新出现(我没想到这一点!),并且命令给我留下了跷跷板作为我的当前分支。从那里,我知道该怎么做。

It turns out that everything is all right. Somehow the git rebase --abort caused the seesaw branch to re-appear (I wasn't expecting that!), and the command left me with seesaw as my current branch. From there, I knew what to do.

推荐答案

根据与@cdhowie的意见,我怀疑 __ git_ps1 正在处理git的变基情况有所不同。所以,我看着源,发现如下行:

Based on comments with @cdhowie, I got suspicion that __git_ps1 is handling the git rebase scenario differently. So I looked into the source and found the following lines:

...
if [ -f "$g/rebase-merge/interactive" ]; then
    r="|REBASE-i"
    b="$(cat "$g/rebase-merge/head-name")"
elif [ -d "$g/rebase-merge" ]; then
    r="|REBASE-m"
    b="$(cat "$g/rebase-merge/head-name")"
...

所以只要在的git的/重订合并存在,你会得到错误分支,即使你已经移动到另一个分支。

So as long of the .git/rebase-merge exists you will be getting the "wrong" branch, even if you have moved to another branch.

git的变基--abort 将修复它。或删除的.git /变基合并

这篇关于在我的bash提示符,$(__ git_ps1)告诉我什么是错的,但什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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