git 使用来自 MinGW 的 msysGit,反之亦然

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5885393/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:24:54  来源:igfitidea点击:

Using msysGit from MinGW and vice versa

gitcompilationmingwmsysgitmsys

提问by tbolender

I am using git as my revision control system. To do so, I installed msysGit to checkout my repositories on MSW. Now I want to compile my programs with MinGW and found this "problem" for me: When I install MinGW and MSYS via mingw-get I can compile my program, no problem. But I can not access git. When I use the Git Bash, I can work with git, but can not compile.

我使用 git 作为我的版本控制系统。为此,我安装了 msysGit 来检查我在 MSW 上的存储库。现在我想用 MinGW 编译我的程序,并为我发现了这个“问题”:当我通过 mingw-get 安装 MinGW 和 MSYS 时,我可以编译我的程序,没问题。但我无法访问 git。当我使用 Git Bash 时,我可以使用 git,但无法编译。

Is there any possibility to:

有没有可能:

  • install MinGW "into" Git Bash (because it already contains msys, didn't it?) OR
  • to set "links" between both installations to make it work.
  • 将 MinGW 安装到“Git Bash”中(因为它已经包含了 msys,不是吗?)或者
  • 在两个安装之间设置“链接”以使其工作。

I would prefere the way I can keep both packages up to date more easily.

我更喜欢可以更轻松地使两个软件包保持最新的方式。

Thanks in advance :)

提前致谢 :)

采纳答案by manojlds

How did you install Msysgit? Did you choose the third option in the screen where it asks for PATH setup?

你是如何安装 Msysgit 的?您是否在要求 PATH 设置的屏幕中选择了第三个选项?

enter image description here

在此处输入图片说明

(above screenshot from: http://ekkescorner.files.wordpress.com/2010/02/git-windows-msysgit-install-3.png.)

(以上截图来自:http: //ekkescorner.files.wordpress.com/2010/02/git-windows-msysgit-install-3.png。)

You have to choose the third option or even second might suffice.

您必须选择第三个选项,甚至第二个可能就足够了。

Below is screenshot from my MingW

下面是我的 MingW 截图

enter image description here

在此处输入图片说明

Anyway, it's all about setting proper path to the git.exe in msysgit, or am I missing something?

无论如何,这都是关于在 msysgit 中设置 git.exe 的正确路径,还是我遗漏了什么?

回答by Guilherme

You can add a symbolic link to git in MinGW, if you chose the second option.

如果您选择了第二个选项,您可以在 MinGW 中添加到 git 的符号链接。

So if your msysgit installation is in C:\Program Files (x86)\Git Open the MinGW shell and type:

所以如果你的 msysgit 安装在 C:\Program Files (x86)\Git 打开 MinGW shell 并输入:

cd /usr/bin
ln -s /c/Program\ Files\ \(x86\)/Git/bin/git git

This will create a symbolic link called git in MinGW's /usr/bin pointing to the msysgit installation. Then you can use the git command anywhere from the MinGW shell.

这将在 MinGW 的 /usr/bin 中创建一个名为 git 的符号链接,指向 msysgit 安装。然后你可以在 MinGW shell 的任何地方使用 git 命令。

回答by oenpelli

You need to fix up the PATH so that you are running the external commands that match the msys or msysgit environment. Depending on how you installed these two shell environments one of them will be first in the PATH so regardless of which bash you are running you will be running external commands from the bin directory which is first in the PATH.

您需要修复 PATH,以便您运行与 msys 或 msysgit 环境匹配的外部命令。根据您安装这两个 shell 环境的方式,其中一个将首先出现在 PATH 中,因此无论您运行的是哪个 bash,您都将从位于 PATH 中的第一个 bin 目录中运行外部命令。

You can test this by running ls.exe from the different bash shells, I found one worked and one didn't but when I fixed up the PATH they both worked.

您可以通过从不同的 bash shell 运行 ls.exe 来测试这一点,我发现一个有效,一个没有,但是当我修复 PATH 时,它们都有效。

I tried to work out a clever script that would work for both but it is difficult as they both map their own bin directory to /bin. When I got sick of trying to work this out I created msys.sh and msysgit.sh with the line:

我试图设计出一个对两者都适用的巧妙脚本,但这很困难,因为它们都将自己的 bin 目录映射到 /bin。当我厌倦了尝试解决这个问题时,我使用以下行创建了 msys.sh 和 msysgit.sh:

export PATH=/c/MinGW/msys/1.0/bin:/c/MinGW/bin:${PATH}

or

或者

export PATH="/c/Program Files (x86)/Git/bin:${PATH}"

respectively. These files need to be sourced into the environment you are running. For example:

分别。这些文件需要被导入到您正在运行的环境中。例如:

source ./msys.sh

You actually only need one script as one environment will work, but I also installed RubyDevKit which had the same problem so it seemed simpler to create a script for each environment.

你实际上只需要一个脚本,因为一个环境可以工作,但我还安装了 RubyDevKit,它有同样的问题,所以为每个环境创建一个脚本似乎更简单。

回答by mark gu

If you want the path change every time you start your git bash on windows. You need do the following steps:

如果您希望每次在 Windows 上启动 git bash 时都更改路径。您需要执行以下步骤:

  1. In windows run, type "git bash"
  2. Vim ~/.profile
  3. Add "export PATH=/c/MinGW/msys/1.0/bin:/c/MinGW/bin:${PATH}" to last line of the file.(The MinGW should locate in C:\MinGW)
  4. :wq, exist the vim.
  5. exit the git bash, and restart again
  1. 在 Windows 运行中,输入“git bash”
  2. Vim ~/.profile
  3. 将“export PATH=/c/MinGW/msys/1.0/bin:/c/MinGW/bin:${PATH}”添加到文件的最后一行。(MinGW应该位于C:\MinGW)
  4. :wq,存在vim。
  5. 退出 git bash,然后重新启动