windows 'git' 不被识别为内部或外部命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4492979/
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
'git' is not recognized as an internal or external command
提问by Jason Kim
I have an installation of Git for Windows, but when I try to use the git
command in Command Prompt, I get the following error:
我安装了适用于 Windows 的 Git,但是当我尝试git
在命令提示符中使用该命令时,出现以下错误:
'git' is not recognized as an internal or external command,
operable program or batch file.
How do I fix this problem?
我该如何解决这个问题?
回答by Abizern
Have you correctly set your PATH
to point at your Git installation?
您是否正确设置PATH
了指向您的 Git 安装?
You need to add the following paths to PATH
:
您需要将以下路径添加到PATH
:
C:\Program Files\Git\bin\
C:\Program Files\Git\cmd\
C:\Program Files\Git\bin\
C:\Program Files\Git\cmd\
And check that these paths are correct – you may have Git installed on a different drive, or under Program Files (x86)
. Correct the paths if necessary.
并检查这些路径是否正确——您可能将 Git 安装在不同的驱动器上,或安装在Program Files (x86)
. 如有必要,请更正路径。
Modifying PATH
on Windows 10:
PATH
在 Windows 10 上修改:
- In the Start Menu or taskbar search, search for "environment variable".
- Select "Edit the system environment variables".
- Click the "Environment Variables" button at the bottom.
- Double-click the "Path" entry under "System variables".
- With the "New" button in the PATH editor, add
C:\Program Files\Git\bin\
andC:\Program Files\Git\cmd\
to the end of the list. - Close and re-open your console.
- 在开始菜单或任务栏搜索中,搜索“环境变量”。
- 选择“编辑系统环境变量”。
- 单击底部的“环境变量”按钮。
- 双击“系统变量”下的“路径”条目。
- 使用 PATH 编辑器中的“新建”按钮,将
C:\Program Files\Git\bin\
和添加C:\Program Files\Git\cmd\
到列表的末尾。 - 关闭并重新打开您的控制台。
Modifying PATH
on Windows 7:
PATH
在 Windows 7 上修改:
- Right-click "Computer" on the Desktop or Start Menu.
- Select "Properties".
- On the very far left, click the "Advanced system settings" link.
- Click the "Environment Variables" button at the bottom.
- Double-click the "Path" entry under "System variables".
- At the end of "Variable value", insert a
;
if there is not already one, and thenC:\Program Files\Git\bin\;C:\Program Files\Git\cmd\
. Do not put a space between;
and the entry. - Close and re-open your console.
- 右键单击桌面或开始菜单上的“计算机”。
- 选择“属性”。
- 在最左侧,单击“高级系统设置”链接。
- 单击底部的“环境变量”按钮。
- 双击“系统变量”下的“路径”条目。
- 在“变量值”的末尾,
;
如果还没有,则插入a ,然后插入C:\Program Files\Git\bin\;C:\Program Files\Git\cmd\
。不要在;
和 条目之间放置空格。 - 关闭并重新打开您的控制台。
If these instructions weren't helpful, feel free to look at some others:
如果这些说明没有帮助,请随时查看其他说明:
- How to set the path and environment variables in Windows(Computer Hope)
- How to edit your system PATH for easy command line access in Windows(How-To Geek)
- How to set Path environment variables in Windows 10(Addictive Tips)
- What are PATH and other environment variables, and how can I set or use them?(Super User)
- 如何在Windows中设置路径和环境变量(Computer Hope)
- 如何编辑系统路径以便在 Windows 中轻松访问命令行(How-To Geek)
- 如何在 Windows 10 中设置 Path 环境变量(令人上瘾的提示)
- 什么是 PATH 和其他环境变量,我该如何设置或使用它们?(超级用户)
回答by Ghanshayam Patel
Did you open the cmd
prompt before installation of git? If so, close and reopen it.
cmd
安装git之前有没有打开提示?如果是这样,请关闭并重新打开它。
回答by Skitty
- Go to My Computer => Local Disk(C:) => Program Files(x86) => Git => cmd
- Right Click the git => Select Properties
- Under the locationCopy the text eg - C:\Program Files (x86)\Git\cmd
- Come back to the Desktop
- Right-click My Computer
- Select property
- Open Advanced
- Click Environment Variables
- In the System variables Find the Variable call Path
- Click the variable
- Click the Edit Button
- Select the Variable valueText Box .
- Go to the edge of the text and put semicolon(;)
- Then Right-click and press Paste
- Press Ok
- 转到我的电脑 => 本地磁盘(C:) => 程序文件(x86) => Git => cmd
- 右键单击git => 选择属性
- 在位置复制文本例如 - C:\Program Files (x86)\Git\cmd
- 回到桌面
- 右键单击我的电脑
- 选择属性
- 打开高级
- 单击环境变量
- 在系统变量中找到变量调用路径
- 单击变量
- 单击编辑按钮
- 选择变量值文本框。
- 转到文本的边缘并放置分号(;)
- 然后右键单击并按粘贴
- 按确定
回答by surinder singh
If you are using GitHub for Windows(GitHub's old Git GUI that is no longer available for download, not the new Electron-based GitHub Desktop), you have an installation of Git under:
如果您使用GitHub for Windows(GitHub 的旧 Git GUI 不再可供下载,而不是新的基于 Electron 的GitHub Desktop),则您在以下位置安装了 Git:
C:\Users\<YOUR USERNAME>\AppData\Local\GitHub\PortableGit_8810fd5c2c79c73adcc73fd0825f3b32fdb816e7\cmd
Expand this path, and add it to PATH
.
展开此路径,并将其添加到PATH
.
回答by Justice O.
回答by Sandeep kr gupta
If you want to setup for temporary purpose, just execute below command.
如果您想临时设置,只需执行以下命令。
- open command prompt < run --> cmd >
- Run below command.
set PATH=C:\Program Files\Git\bin;%PATH% - Type git, it will work.
- 打开命令提示符 < 运行 --> cmd >
- 运行下面的命令。
设置 PATH=C:\Program Files\Git\bin;%PATH% - 输入 git,它会起作用。
This is valid for current window/cell only, if you will close command prompt, everything will get vanish.
For permanently setting, set GIT in environment variable.
这仅对当前窗口/单元格有效,如果您关闭命令提示符,一切都会消失。
如需永久设置,请在环境变量中设置 GIT。
a. press Window+Pause
b. click on Advance system setting.
一种。按窗口+暂停
b. 点击高级系统设置。
c. Click on Environment variable under Advance Tab.
C。单击高级选项卡下的环境变量。
d. Edit Path Variable.
d. 编辑路径变量。
e. Add below line in end of statement.
;c:\Program Files\Git\bin;
e. 在语句末尾添加以下行。
;c:\Program Files\Git\bin;
f. Press OK!!
g. Open new command prompt .
h. Type gitand press Enter
F。按确定!!
G。打开新的命令提示符。
H。类型混帐,然后按Enter
Thanks
谢谢
回答by Jeeves
Start->All Programs->Git->Git Bash
开始->所有程序->Git->Git Bash
Takes you directly to the Git Shell.
将您直接带到 Git Shell。
回答by miva2
Git should be configured in your path variables.
Git 应该在你的路径变量中配置。
(on Windows 7)
Open the start button and type in environment
. Click on Edit the system environment variables
. Click Environment Variables
. Scroll down to the Path
variable in the bottom box
named system variables
. Click edit
. In the bottom box named variable value
add the path to your git bin folder. (for me this is C:\Program Files (x86)\Git\bin
but it can be different for you.) If there is no semicolon (;
) between your path and the previous one, add one there. Make sure you don't delete the other path variables, only add the git bin folder to the end.
(在 Windows 7 上)打开开始按钮并输入environment
. 单击Edit the system environment variables
。单击Environment Variables
。向下滚动Path
到底部框中名为的变量system variables
。单击edit
。在名为的底部框中variable value
添加到您的 git bin 文件夹的路径。(对我来说是这样,C:\Program Files (x86)\Git\bin
但对您来说可能不同。)如果;
您的路径和前一个路径之间没有分号 ( ),请在那里添加一个。确保不删除其他路径变量,只将 git bin 文件夹添加到最后。
This worked for me. Git is now available through the command line.
Open the command line and type git
to verify if it worked for you.
这对我有用。现在可以通过命令行使用 Git。打开命令行并键入git
以验证它是否适合您。
回答by Ali Adravi
Windows 8
视窗 8
- Drag the Mouse pointer to the Right bottom corner of the screen
- Click on the Search icon and type: Control Panel
- Click on -> Control Panel -> System -> Advanced
- Click on Environment Variables, under System Variables, find PATH, and click on it.
- 将鼠标指针拖到屏幕右下角
- 单击搜索图标并键入:控制面板
- 点击 -> 控制面板 -> 系统 -> 高级
- 单击 Environment Variables,在 System Variables 下,找到 PATH,然后单击它。
Add
添加
C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Git\cmd
C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Git\cmd
It worked for me
它对我有用
回答by Jose A
Yo! I had lots of problems with this. It seems that Github brings its own console which you need to look for in your drive. I managed to finally run it by doing the following:
哟!我有很多问题。似乎 Github 带来了自己的控制台,您需要在驱动器中查找它。我设法通过执行以下操作最终运行它:
- Press Start.
- Search for "GitHub" (without quotes)
- Right click on "GitHub" and select "Open File Location"
- 按开始。
- 搜索“GitHub”(不带引号)
- 右键单击“GitHub”并选择“打开文件位置”
*This shall open *
*这将打开*
C:\Users\UserName\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\GitHub, Inc
Where usernameis your PC's username
其中username是您 PC 的用户名
- Look for a program called "Git Shell". Double click on it.
- 寻找一个名为“Git Shell”的程序。双击它。
This will open a PowerShell command prompt. Then you can run your git commands normally on it.
这将打开 PowerShell 命令提示符。然后你就可以正常运行你的 git 命令了。