git.cmd vs git.exe - 有什么区别,应该使用哪一个? [英] git.cmd vs git.exe - what is the difference and which one should be used?

查看:2017
本文介绍了git.cmd vs git.exe - 有什么区别,应该使用哪一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个粗略的想法,git.cmd只是一个包装(但默认添加到PATH中),但是我发现git.exe也适用,我打算用它作为这个问题(对它的评论,而对于XP64上的chcp)。这是否会因为任何原因而被推荐?另外,git.cmd真的需要在第一个地方吗?

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?

注意:我所指的chcp问题不是由于缺少PATH条目导致的,如'ccp'不被识别为内部或外部命令,可操作程序或批处理文件。在Windows PC上

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

推荐答案

git.cmd no在当前版本的msysgit中存在更长时间(例如1.8.0)。 git.cmd 是一个包装,被一个名为 git.exe 的新包装所取代。这不会与实际的 git.exe 混淆。

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目录在%ProgramFiles(x86)%%ProgramFiles%中,您将看到以下结构:

If you take a look at the Git directory in %ProgramFiles(x86)% or %ProgramFiles%, you will see the following structure:

Git
|-- bin
|   |-- git.exe
|-- cmd
    |-- git.exe

为了正确设置从cmd.exe使用git的环境,包装已经存在于msysgit很长一段时间。如果您使用的是包含的bash shell,它将直接运行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.

您可以在此比较旧的cmd版本与新的可执行封装器:

You can compare the old cmd version with the new executable wrapper here:


  1. git.cmd

  2. git.exe包装器

  1. git.cmd
  2. git.exe wrapper

需要担心这个魔法,只要理解你应该从msysgit bash环境以外的任何东西中调用封装器。当你将git添加到安装程序的路径中时,它就是添加的Git \ cmd目录。我不建议将所有包含的实用程序添加到您的系统路径中,因为这可能会导致很多问题,特别是如果您有其他msys或cygwin安装。我从来没有在最近的内存中尝试过它,但我可以想象它将 cmd bin 目录放入您的路径, 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.

对于我来说,新git.exe有一个巨大的优势包装器:它使调用git的代码更加便携。以前,如果我编写了一个名为git的python脚本,我必须在shell环境下执行命令( subprocess.Popen() shell = True )或者显式运行cmd文件。现在,无论操作系统如何,我都可以使用git作为名称执行进程。这是因为Windows上的CreateProcess()不会执行批处理文件( .cmd .bat 的别名) ,你需要调用 cmd.exe 来执行它。

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.cmd vs git.exe - 有什么区别,应该使用哪一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆