博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
git 命令 显示 分支_从命令行显示git分支
阅读量:2514 次
发布时间:2019-05-11

本文共 2059 字,大约阅读时间需要 6 分钟。

git 命令 显示 分支

Whether it's simply submitting pull requests or being snobby enough to use vim as a text editor, web developers and designers spend an awful lot of time working from command line.  If you do work with git, you know it's important to keep track of your branches, especially when it comes to knowing which branch you're currently on.

无论是简单地提交拉取请求,还是为了使用vim作为文本编辑器而之以鼻,Web开发人员和设计人员都花费大量时间在命令行上工作。 如果您确实使用git,那么就知道跟踪分支非常重要,尤其是要知道您当前在哪个分支上时。

You could frequently execute git branch to ensure you're on the branch you'd prefer to be on, but that's a lot of unnecessary repetition.  After all, with the amount of work we do from command line, there should be a way to always display that information...and there is.  Let me show you how to always show the current checked out branch within the command line display!

您可以经常执行git branch以确保您位于希望加入的分支上,但这是很多不必要的重复。 毕竟,通过我们在命令行中完成的大量工作,应该有一种始终显示该信息的方法。 让我向您展示如何始终在命令行显示中显示当前已检出的分支!

Start by opening your .bash_profile file -- this file is typically used to and set environment variables.  Add the following to the .bash_profile file:

首先打开.bash_profile文件-该文件通常用于和设置环境变量。 将以下内容添加到.bash_profile文件中:

# Slightly modified from: https://coderwall.com/p/fasnya/add-git-branch-name-to-bash-prompt# Show current git branch in command lineparse_git_branch() {     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'}export PS1="\[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "

PS1 represents the leading text display before each line execute in the command line.  With the directive above your command line will display like:

PS1表示在命令行中每行执行之前的前导文本显示。 使用上面的指令,命令行将显示如下:

Show Git Branch

Always seeing the current branch name (if any) is a time saver and blanket of security for those of use who use git for our projects.  Do yourself the favor of adding this tiny snippet to your .bash_profile and thank me later!

对于那些在我们的项目中使用git的用户而言,始终看到当前的分支名称(如果有的话)可以节省时间和安全。 帮自己把这个小片段添加到您的.bash_profile ,稍后再感谢我!

Are you a Windows user? Check out to achieve the same functionality!

您是Windows用户吗? 查看以实现相同的功能!

翻译自:

git 命令 显示 分支

转载地址:http://ccpwd.baihongyu.com/

你可能感兴趣的文章
css基础
查看>>
如何在tomcat中如何部署java EE项目
查看>>
【Python基础教程第2版】——第二讲:列表和元组
查看>>
小常识
查看>>
使用vscode开发python
查看>>
swift--调用系统单例实现打电话
查看>>
0038-算一算是一年中的第几天
查看>>
51nod 1094 【水题】
查看>>
003.第一个动画:绘制直线
查看>>
ng-深度学习-课程笔记-2: 神经网络中的逻辑回归(Week2)
查看>>
正则表达式的搜索和替换
查看>>
个人项目:WC
查看>>
地鼠的困境SSL1333 最大匹配
查看>>
flume+elasticsearch+kibana遇到的坑
查看>>
【MM系列】在SAP里查看数据的方法
查看>>
C#——winform
查看>>
CSS3 transform制作的漂亮的滚动式导航
查看>>
《小强升职记——时间管理故事书》读书笔记
查看>>
Alpha 冲刺(3/10)
查看>>
Kaldi中的Chain模型
查看>>