在我的 bash 提示符中, $(__git_ps1) 告诉我出了什么问题,但是什么问题呢?

发布于 2024-12-02 16:56:00 字数 1647 浏览 0 评论 0原文

我已经破解了我的 bash 提示符(理论上)告诉我当前所在的 git 分支。但是输出表明出了问题:

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

这是我的 .bash_profile 文件中的相关代码(我将放一个更大的代码块)在这个问题的末尾):

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

正如你所看到的,$(__git_ps1)返回(seesaw|REBASE-i),即使我不再有跷跷板 分支! (我确实有一个,它有一个与我在 github 上的远程 seesaw 分支相关的变基问题。我想我解决了这个问题,并且 gitbranch -r seesaw 成功删除了本地副本。)

我很确定 (seesaw|REBASE-i) 告诉我出了什么问题,但我不知道它是什么。

感谢您提出的任何建议。 (后面是 .bash_profile 块)

-------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 \$"

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

ADDENDUM

@cdhowie 和 @manojlds,你们的 git 知识给我留下了深刻的印象!

git rebase --abort 导致信息更改为 (seesaw)。不幸的是,我在硬盘上的任何位置都找不到 rebase-merge (或 .git)。我使用的是 Mac,它对许多 FOSS 工具做了奇怪的事情。 (我确实在 /usr/local/git 中找到了 git 本身。) /Library/Application Support 或 ~//Library/Application Support 中也没有任何内容。

(稍后)

事实证明,一切都好。不知何故, git rebase --abort 导致 seesaw 分支重新出现(我没想到会这样!),并且该命令让我将 seesaw 作为当前分支。从那时起,我知道该怎么做。

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

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 \$"

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.)

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

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 \$"

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

ADDENDUM

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

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.

(still later)

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌伤ぢ 2024-12-09 16:56:00

根据 @cdhowie 的评论,我怀疑 __git_ps1 正在以不同的方式处理 git rebase 场景。因此,我查看了源代码,发现了以下几行:

...
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/rebase-merge 存在,即使您已移动到另一个分支,您也会得到“错误”的分支。

git rebase --abort 将修复它。或者删除 .git/rebase-merge

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")"
...

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 rebase --abort will fix it. Or delete .git/rebase-merge

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文