在 IntelliJ IDEA 的终端工具窗口中无法识别 git 命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27678608/
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-19 10:38:52  来源:igfitidea点击:

git command is not recognized on Terminal tool window in IntelliJ IDEA

gitintellij-idea

提问by Francesco Menzani

I am trying to use Bitbucket with IntelliJ IDEA Community Edition.

我正在尝试将 Bitbucket 与 IntelliJ IDEA 社区版一起使用。

  1. I went to File >> Settings... >> Pluginsand installed the Bitbucketplugin. The Git Integrationplugin seems enabled already.

  2. I went to File >> Settings... >> Other Settings >> Bitbucketand logged in.

  3. I installed Git-1.9.5-preview20141217.

  4. I went to File >> Settings... >> Version Control >> Gitand set Path to Git executableto C:\Program Files (x86)\Git\bin\git.exe. Testing will find it.

  5. I activated all this under VCS. I saw a successful message.

  1. 我去文件>>设置...>>插件并安装了Bitbucket插件。在Git的集成插件似乎已经启用。

  2. 我去文件>>设置...>>其他设置>>Bitbucket并登录。

  3. 我安装了Git-1.9.5-preview20141217

  4. 我转到File >> Settings... >> Version Control >> Git并将Git 可执行文件的路径设置为C:\Program Files (x86)\Git\bin\git.exe。测试会发现。

  5. 我在VCS下激活了所有这些。我看到一条成功的消息。

Then I created a repository on a team. Now I must do the first commit, right?

然后我在一个团队中创建了一个存储库。现在我必须做第一次提交,对吗?

Already have a Git repository on your computer? Let's push it up to Bitbucket.

您的计算机上已经有一个 Git 存储库?让我们把它推到 Bitbucket。

cd /path/to/my/repo
git remote add origin https://[email protected]/sphx/s.git
git push -u origin --all # pushes up the repo and its refs for the first time
git push -u origin --tags # pushes up any tags

I opened View >> Tool Windows >> Terminal.

我打开了View >> Tool Windows >> Terminal

"git" is not recognized as an internal or external command

“git”不被识别为内部或外部命令

采纳答案by Bohuslav Burghardt

The terminal tool window is just a terminal emulator for a command shell. In case of Windows that shell defaults to cmd, which is completely independent of the IDE settings. So in order for that to work you must have git in PATHenvironment variable.

终端工具窗口只是命令外壳的终端模拟器。在 Windows 的情况下,shell 默认为 cmd,它完全独立于 IDE 设置。因此,为了使其工作,您必须在PATH环境变量中使用 git 。

You can do it this way:

你可以这样做:

  1. Go to Control panel/System/Advanced System Settings
  2. Click Environment variables
  3. Select PATHand click Edit
  4. Append following string at the end of the variable value: ;C:\Program Files (x86)\Git\bin
    • The semicolon is important, because individual PATH entries are delimited by it
    • The path to git bin directory might be different on your system
  1. 进入控制面板/系统/高级系统设置
  2. 单击环境变量
  3. 选择PATH并点击编辑
  4. 在变量值的末尾附加以下字符串: ;C:\Program Files (x86)\Git\bin
    • 分号很重要,因为单个 PATH 条目由它分隔
    • git bin 目录的路径在您的系统上可能不同

This works on Windows 8.1. It might be a little different on older versions of Window. Just in case here is a linkwhich covers this procedure on more Windows versions.

这适用于 Windows 8.1。在旧版本的 Window 上可能会有所不同。以防万一这里有一个链接,它涵盖了更多 Windows 版本的此过程。

Or you could set Git Bash as the shell for the Terminal tool window. Personally I prefer this approach on Windows computers. You can do it by going into Settings/Terminaland setting Shell pathto something like "C:\Program Files (x86)\Git\bin\sh.exe" --login -i(this might be different on your computer).

或者您可以将 Git Bash 设置为终端工具窗口的外壳。我个人更喜欢在 Windows 计算机上使用这种方法。您可以通过进入Settings/Terminal并将Shell 路径设置为类似"C:\Program Files (x86)\Git\bin\sh.exe" --login -i(这可能在您的计算机上有所不同)来实现。