从 Windows 通过 Cygwin 运行 Git
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15692890/
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
Running Git through Cygwin from Windows
提问by jh_
I have started using Cygwin recently for other purposes and already have Git installed on my PC. I understand I can run the executable and install Git into Cygwin, but since I already have it installed I would like Cygwin to just use my Windows installation. I have tried researching how to make the path redirect in various ways but with no success, can someone help me out?
我最近开始将 Cygwin 用于其他目的,并且已经在我的 PC 上安装了 Git。我知道我可以运行可执行文件并将 Git 安装到 Cygwin 中,但是由于我已经安装了它,我希望 Cygwin 只使用我的 Windows 安装。我曾尝试研究如何以各种方式使路径重定向但没有成功,有人可以帮助我吗?
回答by VonC
I confirm that git and msysgit can coexist on the same computer, as mentioned in "Which GIT version to use cygwin or msysGit or both?".
我确认 git 和 msysgit 可以在同一台计算机上共存,如“哪个 GIT 版本使用 cygwin 或 msysGit 或两者?”中所述。
Git for Windows (msysgit) will run in its own shell (dos with
git-cmd.bat
or bash withGit Bash.vbs
)
Update 2016: msysgit is obsolete, and the new Git for Windowsnow uses msys2Git on Cygwin, after installing its package, will run in its own cygwin bash shell.
Windows 版 Git (msysgit) 将在自己的 shell 中运行(dos with
git-cmd.bat
或 bash withGit Bash.vbs
)
2016 年更新:msysgit 已过时,新版Git for Windows现在使用 msys2Cygwin 上的 Git,在安装其包后,将在其自己的 cygwin bash shell 中运行。
- Finally, since Q3 2016 and the "Windows 10 anniversary update", you can use Git in a bash (an actual Ubuntu(!) bash).
- 最后,自 2016 年第三季度和“Windows 10 周年更新”以来,您可以在 bash(实际的 Ubuntu(!) bash)中使用Git。
In there, you can do a sudo apt-get install git-core
and start using giton project-sources present either on the WSL container's "native" file-system (see below), or in the hosting Windows's file-system through the /mnt/c/...
, /mnt/d/...
directory hierarchies.
在那里,您可以在 WSL 容器的“本机”文件系统(见下文)或通过,目录层次结构托管 Windows 的文件系统中的项目源上执行sudo apt-get install git-core
并开始使用git。/mnt/c/...
/mnt/d/...
Specifically for the Bash on Windowsor WSL(Windows Subsystem for Linux):
专门针对Windows 上的Bash或WSL(Linux 的 Windows 子系统):
- It is a light-weight virtualization container (technically, a "Drawbridge" pico-process,
- hosting an unmodified "headless" Linux distribution (i.e. Ubuntuminus the kernel),
- which can execute terminal-based commands (and even X-server client apps if an X-server for Windowsis installed),
- with emulated access to the Windows file-system(meaning that, apart from reduced performance, encodingsfor files in
DrvFs
emulated file-system may not behave the same as files on the nativeVolFs
file-system).
- 它是一个轻量级的虚拟化容器(从技术上讲,一个“吊桥”微微进程,
- 托管未经修改的“无头”Linux 发行版(即Ubuntu减去内核),
- 它可以执行基于终端的命令(如果安装了适用于Windows的X-server,甚至可以执行 X-server 客户端应用程序),
- 与仿真的访问Windows文件系统(这意味着,除了降低性能,编码为文件
DrvFs
仿真文件系统可能无法正常使用一样的文件本机VolFs
文件系统)。
- Unfortunately, it cannot invoke back into Windowsexecutables, or
- interact with any native drivers (i.e. so no Graphic card, no USB drives yet).
- 不幸的是,它不能调用回Windows可执行文件,或者
- 与任何本机驱动程序交互(即没有图形卡,还没有 USB 驱动器)。
回答by Steven Penny
I can tell you from personal experience this is a bad idea. Native Windows programs cannot accept Cygwin paths. For example with Cygwin you might run a command
我可以从个人经验告诉你,这是一个坏主意。本机 Windows 程序不能接受 Cygwin 路径。例如,使用 Cygwin,您可能会运行一个命令
grep -r --color foo /opt
with no issue. With Cygwin /
represents the root directory. Native Windows programs have no concept of this, and will likely fail if invoked this way. You should not mix Cygwin and Native Windows programs unless you have no other choice.
没有问题。用 Cygwin/
代表根目录。本机 Windows 程序没有这个概念,如果以这种方式调用,很可能会失败。除非别无选择,否则不应混合使用 Cygwin 和本机 Windows 程序。
Uninstall what Git you have and install the Cygwin git package, save yourself the headache.
卸载你所拥有的 Git 并安装 Cygwin git 包,省去你的头痛。
回答by Jonathan
Isn't this as simple as adding your git install to your Windows path?
这不是像将 git install 添加到 Windows 路径一样简单吗?
E.g. Win+Rrundll32.exe sysdm.cpl,EditEnvironmentVariables
Edit...PATH appending your Mysysgit install path e.g. ;C:\Program Files (x86)\Git\bin
. Re-run Cygwin and voila. As Cygwin automatically loads in the Windows environment, so too will your native install of Git.
例如Win+ Rrundll32.exe sysdm.cpl,EditEnvironmentVariables
Edit...PATH 附加您的 Mysysgit 安装路径,例如;C:\Program Files (x86)\Git\bin
. 重新运行 Cygwin,瞧。由于 Cygwin 会自动加载到 Windows 环境中,因此您的 Git 本地安装也会自动加载。
回答by inselberg
call your (windows-)git with cygpath
as parameter, in order to convert the "calling path". I m confused why that should be a problem.
使用cygpath
作为参数调用您的(windows-)git,以转换“调用路径”。我很困惑为什么这应该是一个问题。