Git:使用Windows的GitHub客户端在PATH中安装Git

问题描述:

在Windows上使用GitHub客户端时,如何在PATH中安装Git?

How do I install Git in my PATH when using the GitHub client for Windows?

我遇到了错误,因为显然Git未安装在PATH中.例如,使用Atom尝试安装Linter插件会出现以下错误:

I'm running into errors because apparently Git is not installed in PATH. For example, using Atom, trying to install the Linter plugin gives this error:

npm ERR! not found: git
npm ERR! 
npm ERR! Failed using git.
npm ERR! This is most likely not a problem with npm itself.
npm ERR! Please check if you have git installed and in your PATH.

适用于Windows的GitHub在安装时是否安装了Git? (它必须,否则它将如何使用Git?)我不想重复安装它...那么如何将已存在的Git添加到PATH中呢?

Does GitHub for Windows install Git when it installs? (It must, otherwise how does it use Git?) I don't want to double-install it... so how do I just add the Git that's already there to PATH?

适用于Windows的GitHub确实安装了自己的Git版本,但没有将其添加到PATH变量中,这很容易做到.以下是有关操作方法的说明:

GitHub for Windows does indeed install its own version of Git, but it doesn't add it to the PATH variable, which is easy enough to do. Here's instructions on how to do it:

  1. 获取Git URL

我们需要获取计算机的Git \cmd目录的URL. Git位于此处:

We need to get the url of the Git \cmd directory your computer. Git is located here:

C:\Users\<user>\AppData\Local\GitHub\PortableGit_<guid>\cmd\git.exe

因此,在您的计算机上,用您的用户替换<user>,然后找出<guid>适用于您的计算机. (guid可能会在每次GitHub更新PortableGit时发生变化,但他们正在为此寻求解决方案.)

So on your computer, replace <user> with your user and find out what the <guid> is for your computer. (The guid may change each time GitHub updates PortableGit, but they're working on a solution to that.)

将其复制并粘贴到命令提示符中(右键单击>粘贴以粘贴到终端中)以验证其是否有效.您应该看到列出了常用Git命令的Git帮助响应.如果看到The system cannot find the path specified.,则网址不正确.正确使用后,请使用以下格式创建指向目录的链接:

Copy it and paste it into a command prompt (right-click > paste to paste in the terminal) to verify that it works. You should see the Git help response that lists common Git commands. If you see The system cannot find the path specified. Then the URL isn’t right. Once you have it right, create the link to the directory using this format:

;C:\Users\<user>\AppData\Local\GitHub\PortableGit_<guid>\cmd

(注意:结尾处是\cmd,现在不再是\cmd\git.exe!)

(Note: \cmd at the end, not \cmd\git.exe anymore!)

在我的系统上,就是这样,您的会有所不同:

On my system, it’s this, yours will be different:

;C:\Users\brenton\AppData\Local\GitHub\PortableGit_7eaa494e16ae7b397b2422033as45d8ff6ac2010\cmd

  • 编辑PATH变量

    导航到环境变量编辑器(说明),然后在系统变量"中找到Path变量. "部分.单击Edit…并将Git的URL粘贴到该字符串的末尾.救!将其拖到记事本中进行编辑可能会更容易,只需确保在粘贴URL之前放入一个分号即可.如果它不起作用,可能是因为此路径被弄乱了,或者是在某处有一个空格(分号周围不应有空格)或在末尾有分号(分号只能分隔URL,在开头或结尾没有分号)细绳).

    Navigate to the Environmental Variables Editor (instructions) and find the Path variable in the "System Variables" section. Click Edit… and paste the URL of Git to the end of that string. Save! It might be easier to pull this into Notepad to do the edit, just make sure you put one semicolon before you paste in the URL. If it doesn't work it’s probably because this path got messed up either with a space in there somewhere (should be no spaces around the semicolon) or a semicolon at the end (semicolons should only separate URLs, no semicolon at beginning or end of string).

    如果有效,您应该可以关闭&重新打开终端并输入git,它将为您提供相同的git帮助文件.然后安装Linter即可. (Atom>文件>设置>包> Linter)

    If it worked, you should be able to close & reopen a terminal and type git and it will give you that same git help file. Then installing the Linter should work. (Atom > File > Settings > Packages > Linter)