windows git.cmd vs git.exe - 有什么区别,应该使用哪一个?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8947140/
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.cmd vs git.exe - what is the difference and which one should be used?
提问by prusswan
I have a rough idea that git.cmd is only a wrapper (but added to PATH by default), but I found out that git.exe works as well and I intend to use it as a workaround to this issue(comments to it rather, regarding chcp on XP64). Would that be not recommended for any reason at all? Also, is git.cmd really needed in the first place?
我有一个粗略的想法,即 git.cmd 只是一个包装器(但默认情况下添加到 PATH 中),但我发现 git.exe 也可以工作,我打算将其用作此问题的解决方法(对它的评论而不是,关于 XP64 上的 chcp)。会不会因为任何原因而完全不推荐?另外,首先真的需要 git.cmd 吗?
Note: The chcp issue I am referring to is not caused by missing PATH entries as in 'chcp' is not recognized as an internal or external command, operable program or batch file. on a Windows PC
注意:我所指的 chcp 问题不是由缺少 PATH 条目引起的,因为在“chcp”中未被识别为内部或外部命令、可运行的程序或批处理文件。在 Windows PC 上
回答by djs
git.cmd
no longer exists in current versions of msysgit (e.g. 1.8.0). git.cmd
was a wrapper that has been replaced by a new wrapped called git.exe
. This is not to be confused with the actual git.exe
.
git.cmd
不再存在于当前版本的 msysgit(例如 1.8.0)中。git.cmd
是一个包装器,已被一个名为git.exe
. 这不要与实际的git.exe
.
If you take a look at the Git directory in %ProgramFiles(x86)%
or %ProgramFiles%
, you will see the following structure:
如果查看%ProgramFiles(x86)%
or中的 Git 目录%ProgramFiles%
,您将看到以下结构:
Git
|-- bin
| |-- git.exe
|-- cmd
|-- git.exe
The wrapper has existed in msysgit for a long time in order to properly set up the environment for using git from cmd.exe. If you are using the included bash shell, it will run git.exe directly.
包装器在 msysgit 中已经存在很长时间了,目的是为了从 cmd.exe 正确设置使用 git 的环境。如果您使用包含的 bash shell,它将直接运行 git.exe。
You can compare the old cmd version with the new executable wrapper here:
您可以在此处将旧的 cmd 版本与新的可执行包装器进行比较:
You don't really need to worry about any of this magic, just understand that you should call the wrapper from anything but the msysgit bash environment. When you add git to the path in the installer, it's the Git\cmd directory that is added. I don't recommend ever adding all the included utilities to your system path, as this can cause a lot of problems, especially if you have other msys or cygwin installations. I've never actually tried it in recent memory, but I would imagine it puts both the cmd
and bin
directories in your path, with cmd
taking precedence.
你真的不需要担心任何这种魔法,只要明白你应该从 msysgit bash 环境以外的任何地方调用包装器。当您将 git 添加到安装程序中的路径时,会添加 Git\cmd 目录。我不建议将所有包含的实用程序添加到您的系统路径中,因为这会导致很多问题,特别是如果您有其他 msys 或 cygwin 安装。在最近的记忆中,我从未真正尝试过它,但我想它会将cmd
和bin
目录放在您的路径中,并具有cmd
优先权。
For me, there is one huge advantage to the new git.exe wrapper: it makes code that calls git more portable. Previously, if I wrote a python script that called git, I would have to either execute the command with a shell environment (subprocess.Popen()
with shell=True
) or run the cmd file explicitly. Now, I can just execute a process with 'git' as the name, regardless of the OS. This is because CreateProcess() on Windows will not execute a batch file (.cmd
is an alias for .bat
), you need to invoke cmd.exe
to execute it.
对我来说,新的 git.exe 包装器有一个巨大的优势:它使调用 git 的代码更具可移植性。以前,如果我编写了一个名为 git 的 python 脚本,我将不得不使用 shell 环境 ( subprocess.Popen()
with shell=True
)执行命令或显式运行 cmd 文件。现在,无论操作系统如何,我都可以执行以“git”为名称的进程。这是因为 Windows 上的 CreateProcess() 不会执行批处理文件(.cmd
是 的别名.bat
),您需要调用cmd.exe
才能执行它。
回答by manojlds
There are three options when you install msysgit.
安装 msysgit 时有三个选项。
The first is that nothing is put on
PATH
and you haveto use Git Bash.The second is that
git.cmd
andgitk.cmd
are added toPATH
so that you can use it in cmd, Powershell, cygwin etc. without affecting other tools that you have on Windows. ( Thisgit.cmd
is a wrapper enabled you to do this, to answer the question).The third ( my favourite) is to add all the tools, and
git.exe
, inPATH
and use this. This will affect Windows tools and you will be able to use the full set of tools that MSYS comes with.
首先是什么都没有穿上
PATH
,你必须使用 Git Bash。第二个是添加了
git.cmd
和gitk.cmd
,PATH
以便您可以在 cmd、Powershell、cygwin 等中使用它,而不会影响您在 Windows 上拥有的其他工具。(这git.cmd
是一个包装器,您可以这样做,以回答问题)。第三个(我的最爱)是添加的所有工具,并且
git.exe
,在PATH
和使用这个。这将影响 Windows 工具,您将能够使用 MSYS 附带的全套工具。
I have always used the third option. I have never seen how it affects me ( I use Powershell and powershell cmdlets and never standard Windows commands) If you are like that and you want Mingw exes at your disposal, go for the third option and you will be good.
我一直使用第三个选项。我从未见过它如何影响我(我使用 Powershell 和 powershell cmdlet,从不使用标准的 Windows 命令)如果你是这样的,并且你想要 Mingw exes 供你使用,请选择第三个选项,你会很好。
回答by Devin M
According to the git for windows installeryou have the option of adding git.exe to your path during the setup. You should be fine using that option.
根据Windows 安装程序的git,您可以选择在安装过程中将 git.exe 添加到您的路径中。使用该选项应该没问题。