git - 在 VCS 中使 shell 提示符显示当前头部

标签 git version-control mercurial dvcs command-prompt

当使用 VCS 时,(我在 Linux 中使用 Mercurial 和 Git,Bash 提示符),有什么方法可以让提示符显示目录中的当前头或标记?

不止一次当我以为我在另一个脑袋里工作时,我开枪打自己的脚,例如,在他们需要 v.02 时 push v0.3 进行测试,或者修补 dev 那么它们需要在 prod 中进行修补,反之亦然。

最佳答案

对于 Mercurial,有 hg-prompt史蒂夫·洛斯。这是 Mercurial 的扩展,它为您提供了一个新的 hg prompt 命令。您将对此命令的调用放入您的 PS1 环境变量中:

export PS1='\u in \w`hg prompt "{on {branch}}{status}{update}" 2>/dev/null` $'

得到类似的提示

user in ~/src/project on feature-branch? $

末尾的 ? 告诉您存储库中有一个未知文件。

Steve 写了一篇 blog post about his Zsh prompt文档中还有更多丰富多彩的提示:

Steve's colorful prompts

关于git - 在 VCS 中使 shell 提示符显示当前头部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8611547/

相关文章:

.net - 如何对仅包含工具的包使用包还原?

git - 在我将 key 添加到 Bitbucket 后,服务器一直要求输入密码

c# - 包含在 .gitignore Visual Studio *.tlog 文件中是否安全?

c# - 连接到 git 的 .NET 的项目结构和构建系统

wordpress - 构建文件夹应该包含在 git repo 中吗?

Mercurial : Tag a particular changeset

php - Laravel 和 PHPStorm 项目的 gitignore 中应该包含什么?

git - jhbuild 存储库克隆失败

ruby-on-rails - Git 或 SVN for Rails 应用程序?

python - Mercurial 中的 "abort: The system cannot find the file specified"