IntelliJ 和 Git 分支名称

我最近从 Eclipse 转移到了 IntelliJ。虽然我是个快捷键瘾君子但这不是我来的原因。

我怀念在包/项目视图中显示 git 分支名称的时候。

有没有人知道如何配置 IntelliJ 来显示项目所在的 git 分支,这样我就不必一直切换回终端并进行检查。

谢谢。

55690 次浏览

That setting doesn't seem to be available with the current Git integration in IntelliJ IDEA.

One workaround would be to start a fake push, because the push Window would then display the current branch.

Push Changes options

(just click cancel instead of going forward with the push:
You have the information you were looking for in the first place.)

As IntelliJ cannot show be my branch I found a way to add the branch to my bash prompt in the terminal. I've added this to my .bashrc file and I get a nice real-time branch indicator.

#Git branch prompt
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}


function proml {
local        BLUE="\[\033[0;34m\]"
local         RED="\[\033[0;31m\]"
local   LIGHT_RED="\[\033[1;31m\]"
local       GREEN="\[\033[0;32m\]"
local LIGHT_GREEN="\[\033[1;32m\]"
local       WHITE="\[\033[1;37m\]"
local  LIGHT_GRAY="\[\033[0;37m\]"
case $TERM in
xterm*)
TITLEBAR='\[\033]0;\u@\h:\w\007\]'
;;
*)
TITLEBAR=""
;;
esac


PS1="${TITLEBAR}$RED\u@\h:\w$GREEN\$(parse_git_branch)$LIGHT_GRAY\$ "
PS2='> '
PS4='+ '
}
proml

EDIT: Ignore this prompt. If you need a GIT prompt use http://volnitsky.com/project/git-prompt/

As of IntelliJ 11 the current Git branch is displayed in the bottom right corner of the status bar. Moreover, clicking on the branch name displays a nice popup with all available branches, and you can invoke some actions on them.


To enable status bar follow the below steps :

 View --> Appearance --> Status Bar [and click to enable/disable]

Coming from Eclipse, I was used to that, so I created a plugin for this:

https://plugins.jetbrains.com/plugin/7802?pr=idea

This is a late answer, if someone is looking for a way to see current git branch in intelliJ.

  1. Install gitbar plugin Git Bar Plugin Repo

enter image description here

  1. Enable status bar and look at the bottom right corner , which shows your current branch as well as you can switch branches from there.

enter image description here

Install IntelliJ Plugin "GitToolBox"

enter image description here

  1. You have to add VCS to the project if not already done
  2. CTRL SHIFT A - opens find
  3. Type - status
  4. Select Status Setting
  5. Click on version control
  6. It would list out the unregistered projects
  7. Select your project then click on + button on the right panel
  8. If You have initialized the git in your local then it would not ask for git path.
  9. Check the other parameters as per your requirement and then apply.

Congrats, you are done provided you have enabled the status bar.

I had an issue whereby I had no git bar or indexing status after moving to IntelliJ 2017.2 - my issue was down to the 'Code Outline' plugin. I deleted it's jar file from C:\Users\[user]\.IntelliJIdea2017.2\config\plugins restarted IntelliJ and I suddenly had my git branch info and indexing status back. Maybe this will help someone else...

Try using git.exe from "/bin" folder

Example Image

Just install GitToolBox plugin.

Side note
The default behavior is to show the file full-path and it will be hard to see the branch names since they're pushed all the way to the right. To solve that you can:

  • Go to File > Settings > Other Settings > GitToolBoxGlobal > Project View and arrange the ordering of the variables in the left pane. E.g. I use the following order: {status} {branch} {tags on head} {location}; this will display something like 3↑ 2↓ master 1.0.0 /path/to/location
  • Or install PathHide plugin to get rid the module path if you don't need it.

There are 2 possible scenarios of not displaying git branch name and here is how to resolve them.

1). Firstly, if your entire status bar is hidden or not display currently; So, you can enable it by easily by Tick the Status Bar option like this:

View -> Appreances -> Then Tick the Status Bar option

Status Bar option

2).If your problem is still displaying the Status Bar in the IDE though, your GIT branch section doesn't display. Then you can use Status Bar Widget option to enable it also.

View -> Appreances -> Ststus Bar Widgets -> Git Branch

State Bar Widget option

Hope this will fix your issue.