IntelliJ 和 Git 分支名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3227546/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 08:43:30  来源:igfitidea点击:

IntelliJ and Git Branch Name

gitintellij-idea

提问by dom farr

I've recently moved from Eclipse to IntelliJ. A challenge as I'm a keyboard shortcut junkie, but that isn't what I'm here about.

我最近从 Eclipse 转移到 IntelliJ。一个挑战,因为我是一个键盘快捷键迷,但这不是我在这里的目的。

I miss having the git branch name shown in the package/project view.

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

Does anyone know of a way to configure IntelliJ to display what git branch the project is in, so I don't have to keep switching back to the terminal and checking.

有谁知道配置 IntelliJ 以显示项目所在的 git 分支的方法,所以我不必一直切换回终端并检查。

Thanks.

谢谢。

回答by LoKi

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.

从 IntelliJ 11 开始,当前的 Git 分支显示在状态栏的右下角。此外,单击分支名称会显示一个包含所有可用分支的漂亮弹出窗口,您可以对它们调用一些操作。



To enable status barfollow the below steps :

要启用,请status bar按照以下步骤操作:

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

回答by R.S

Install IntelliJ Plugin "GitToolBox"

安装 IntelliJ 插件“GitToolBox”

enter image description here

在此处输入图片说明

回答by dom farr

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.

由于 IntelliJ 无法显示为我的分支,我找到了一种将分支添加到终端中 bash 提示符的方法。我已将此添加到我的 .bashrc 文件中,并且我得到了一个不错的实时分支指示器。

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

function proml {
  local        BLUE="\[3[0;34m\]"
  local         RED="\[3[0;31m\]"
  local   LIGHT_RED="\[3[1;31m\]"
  local       GREEN="\[3[0;32m\]"
  local LIGHT_GREEN="\[3[1;32m\]"
  local       WHITE="\[3[1;37m\]"
  local  LIGHT_GRAY="\[3[0;37m\]"
  case $TERM in
    xterm*)
    TITLEBAR='\[3]0;\u@\h:\w##代码##7\]'
    ;;
    *)
    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/

编辑:忽略此提示。如果您需要 GIT 提示,请使用http://volnitsky.com/project/git-prompt/

回答by Sivani Patro

  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.
  1. 如果尚未完成,您必须将 VCS 添加到项目中
  2. CTRL SHIFT A - 打开查找
  3. 类型 - 状态
  4. 选择状态设置
  5. 点击版本控制
  6. 它会列出未注册的项目
  7. 选择您的项目,然后单击右侧面板上的 + 按钮
  8. 如果您已经在本地初始化了 git,那么它不会询问 git 路径。
  9. 根据您的要求检查其他参数,然后应用。

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

恭喜,如果您启用了状态栏,您就完成了。

回答by ilintar

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

来自 Eclipse,我已经习惯了,所以我为此创建了一个插件:

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

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

回答by VonC

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

该设置似乎不适用于IntelliJ IDEA 中当前的Git 集成

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.)

(只需单击取消而不是继续推送:
您首先获得了您正在寻找的信息。)

回答by cherit

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

这是一个迟到的答案,如果有人正在寻找一种在 intelliJ 中查看当前 git 分支的方法。

  1. Install gitbar plugin Git Bar Plugin Repo
  1. 安装 gitbar 插件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.
  1. 启用状态栏并查看右下角,它显示您当前的分支以及您可以从那里切换分支。

enter image description here

在此处输入图片说明

回答by Joe Keene

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\pluginsrestarted IntelliJ and I suddenly had my git branch info and indexing status back. Maybe this will help someone else...

我遇到了一个问题,在移动到 IntelliJ 2017.2 后我没有 git bar 或索引状态 - 我的问题归结为“代码大纲”插件。我从C:\Users\[user]\.IntelliJIdea2017.2\config\plugins重新启动的 IntelliJ 中删除了它的 jar 文件,我突然恢复了我的 git 分支信息和索引状态。也许这会帮助别人......

回答by Gustavo Trevisani

Try using git.exe from "/bin" folder

尝试使用“/bin”文件夹中的 git.exe

Example Image

示例图像

回答by Pado

Just install GitToolBoxplugin.

只需安装GitToolBox插件。

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 Viewand 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 PathHideplugin to get rid the module path if you don't need it.
  • 转到File > Settings > Other Settings > GitToolBoxGlobal > Project View并安排左窗格中变量的顺序。例如,我使用以下顺序:{status} {branch} {tags on head} {location}; 这将显示类似3↑ 2↓ master 1.0.0 /path/to/location
  • 或者安装PathHide插件来摆脱模块路径,如果你不需要它。