【问题标题】:git-bash: show email in Git Bash command prompt variablegit-bash:在 Git Bash 命令提示符变量中显示电子邮件
【发布时间】:2017-05-25 23:22:03
【问题描述】:

Git Bash 中的命令提示符显示当前分支名称(以及其他信息,例如目录名称等),如下所示。

mylogin@SYSNAME MINGW64 ~/path/to/my/repo (master)
$

如何在分支名称中包含 repo 用户个人资料电子邮件?电子邮件是 repo 的 user.email;可以使用命令git config user.email 找到。

我想在我的命令提示符中加上这个值 git config user.email 以及下面给出的分支名称。

mylogin@SYSNAME MINGW64 ~/path/to/my/repo (master|myemail@github.com)
$

请注意我有一个 Windows 系统。

【问题讨论】:

  • git config user.email的结果应用到你的PS1环境变量以获取电子邮件,git rev-parse --abbrev-ref HEAD 2> /dev/null | tr -d '\n'以获取当前分支。
  • 这个你可能会感兴趣:stackoverflow.com/questions/4133904/…

标签: git-bash


【解决方案1】:

嗯... MinGW 方法与“通常”的 bash 方法略有不同,因为它有一个非常丰富的脚本来生成 PS1 Bash 变量。您只需执行以下操作(假设您也使用 64 位):

  • 找到/mingw64/share/git/completion/git-prompt.sh或(%YOUR_GIT_LOCATION%\mingw64\share\git\completion\git-prompt.sh);
  • 修改gitstring环境变量:
    替换local gitstring="$c$b${f:+$z$f}$r$p"
    local gitstring="$c$b${f:+$z$f}$r$p|$(git config user.email)"

我的原始版本和我的带有user.email 设置的版本之间的差异:

diff --git a/git-prompt.sh.BAK b/git-prompt.sh
index 07b52be..2d63680 100644
--- a/git-prompt.sh.BAK
+++ b/git-prompt.sh
@@ -515,7 +515,7 @@ __git_ps1 ()
        fi

        local f="$w$i$s$u"
-       local gitstring="$c$b${f:+$z$f}$r$p"
+       local gitstring="$c$b${f:+$z$f}$r$p|$(git config user.email)"

        if [ $pcmode = yes ]; then
                if [ "${__git_printf_supports_v-}" != yes ]; then

【讨论】:

  • 谢谢Lyubomyr。有效。我可以在我的 git bash 命令提示符中看到分支和电子邮件。
猜你喜欢
  • 2015-06-18
  • 2013-03-30
  • 2017-07-31
  • 2020-07-06
  • 1970-01-01
  • 2013-12-05
  • 1970-01-01
  • 2014-09-12
  • 2015-09-12
相关资源
最近更新 更多