git-bash:在 Git Bash 命令提示符变量中显示电子邮件
git-bash: show email in Git Bash command prompt variable
Git Bash 中的命令提示符显示当前分支名称(以及目录名称等其他信息),如下所示。
mylogin@SYSNAME MINGW64 ~/path/to/my/repo (master)
$
如何将回购用户个人资料电子邮件与分支名称一起包含在内?电子邮件是 repo 的 user.email;可以使用命令 git config user.email
找到它。
我希望在我的命令提示符中包含此值 git config user.email
以及下面给出的分支名称。
mylogin@SYSNAME MINGW64 ~/path/to/my/repo (master|myemail@github.com)
$
请注意我有一个 windows 系统。
嗯... MinGW 方法与 "usual" 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
Git Bash 中的命令提示符显示当前分支名称(以及目录名称等其他信息),如下所示。
mylogin@SYSNAME MINGW64 ~/path/to/my/repo (master)
$
如何将回购用户个人资料电子邮件与分支名称一起包含在内?电子邮件是 repo 的 user.email;可以使用命令 git config user.email
找到它。
我希望在我的命令提示符中包含此值 git config user.email
以及下面给出的分支名称。
mylogin@SYSNAME MINGW64 ~/path/to/my/repo (master|myemail@github.com)
$
请注意我有一个 windows 系统。
嗯... MinGW 方法与 "usual" 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