git 如何在cmder中运行msysgit?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25107769/
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
How do I run msysgit in cmder?
提问by shroy
I was using msysgit and git-bash in cmder when I accidentally exited out of it.
Now I can't seem to figure out how to get to the unix environment I previously had.
当我不小心退出时,我在 cmder 中使用了 msysgit 和 git-bash。
现在我似乎无法弄清楚如何进入我以前拥有的 unix 环境。
Git bash is not recognized as a command.
All I see is the typical command window prompt displaying the C:/User/..
rather than the $~User
.
Git bash 不被识别为命令。
我所看到的只是典型的命令窗口提示显示C:/User/..
而不是$~User
.
How would you restore the git bash session?
您将如何恢复 git bash 会话?
采纳答案by VonC
You can type the full path of your msysgit intallation (2014, Git 1.9.z)to launch a bash session.
您可以键入msysgit 安装的完整路径(2014,Git 1.9.z)来启动 bash 会话。
For instance:
例如:
"c:\prgs\git\PortableGit-1.9.0-preview20140217\Git Bash.vbs"
: will open a new windows"c:\prgs\git\PortableGit-1.9.0-preview20140217\git-bash.bat"
: will open a bash session within the current shell.
"c:\prgs\git\PortableGit-1.9.0-preview20140217\Git Bash.vbs"
: 将打开一个新窗口"c:\prgs\git\PortableGit-1.9.0-preview20140217\git-bash.bat"
: 将在当前 shell 中打开一个 bash 会话。
Those two scripts aren't part of <msysgit/bin>
folder, and are not found in %PATH%
.
这两个脚本不是<msysgit/bin>
文件夹的一部分,也没有在%PATH%
.
As commented by David Graysonand predbelow in the comments, using Git-1.9.5-preview20141217.exe
does result in an installation (in C:\Program File) which does nothave git-bash.bat, and which rely on "Git Bash" shortcut calling C:\Git\bin\sh.exe --login -i
.
正如David Grayson和下面评论中的pred所评论的, usingGit-1.9.5-preview20141217.exe
确实会导致安装(在 C:\Program File 中),它没有git-bash.bat,并且依赖于“Git Bash”快捷方式调用C:\Git\bin\sh.exe --login -i
.
Don't use that setup. Use the much easier and more complete package PortableGit-1.9.5-preview20141217.7zthat you unzip anywhere you want and that you add to your PATH.
不要使用那个设置。使用更简单、更完整的包PortableGit-1.9.5-preview20141217.7z,您可以将其解压缩到任何您想要的位置并添加到您的 PATH 中。
Note: with the new Git for Windows releases (2015, Git 2.y.z), that would be:
注意:对于 Windows 版本的新Git (2015, Git 2.yz),这将是:
- "
c:\prgs\git\PortableGit-2.3.5.8-dev-preview-64-bit\git-bash.exe
": will open a bash session within the current shell.
- "
c:\prgs\git\PortableGit-2.3.5.8-dev-preview-64-bit\git-bash.exe
": 将在当前 shell 中打开一个 bash 会话。
回答by Nick F
An easy way to get this working is to define a custom "bash" task in Cmder, and then configure it to use this task by default.
实现此功能的一种简单方法是在 Cmder 中定义自定义“bash”任务,然后将其配置为默认使用此任务。
- Install cmder_mini(msysgit is already installed, so no need for full version)
- In Cmder, open settings:
Win + Alt + P
- Under Startup> Tasks, add a task called
{bash}
with the following settings:- Task parameters- set the icon:
- Either
/icon "%CMDER_ROOT%\cmder.exe"
(for Cmder icon) or/icon "C:\Program Files (x86)\Git\etc\git.ico"
(for Git icon)
- Either
- Commands- open Git's bash shell:
"C:\Program Files (x86)\Git\bin\sh.exe" -l -new_console:d:%USERPROFILE%
- Task parameters- set the icon:
- Under Startup, set startup options to Specified name task--> {bash}
- 安装cmder_mini(msysgit已经安装,所以不需要完整版)
- 在 Cmder 中,打开设置:
Win + Alt + P
- 在Startup> Tasks 下,添加一个
{bash}
使用以下设置调用的任务:- 任务参数-设置图标:
- 或者
/icon "%CMDER_ROOT%\cmder.exe"
(对于Cmder图标)或/icon "C:\Program Files (x86)\Git\etc\git.ico"
(GIT中图标)
- 或者
- 命令- 打开 Git 的 bash shell:
"C:\Program Files (x86)\Git\bin\sh.exe" -l -new_console:d:%USERPROFILE%
- 任务参数-设置图标:
- 在Startup 下,将启动选项设置为Specified name task--> {bash}
...this will set Git bash as the default console in Cmder.
...这会将 Git bash 设置为 Cmder 中的默认控制台。
nb. The above obviously assumes that Git is installed in "C:\Program Files (x86)\Git" - if that's not the case, you'll need to change the path to point to wherever Git is installed.
备注 上面显然假设 Git 安装在“C:\Program Files (x86)\Git”中——如果不是这样,你需要更改路径以指向安装 Git 的位置。
回答by David Grayson
Run the following command in cmder:
在cmder中运行以下命令:
sh -l
This assumes that Git's "sh" is on your PATH. But if you installed git differently and sh is not found, then try entering the full path to it, for example:
这假设 Git 的“sh”在您的 PATH 上。但是如果你安装了不同的 git 并且没有找到 sh,那么尝试输入它的完整路径,例如:
"C:\Program Files (x86)\Git\bin\sh.exe" -l
If you want to automate this so you don't have to run sh explicitly, then go into cmder/ConEmu's settings and change the {cmd} task to have the command sh -l
and the parameters /dir "%HOME%"
. Then cmder will always start up Git Bash by default, instead of Microsoft's cmd shell.
如果您想自动执行此操作,因此您不必显式运行 sh,请进入 cmder/ConEmu 的设置并更改 {cmd} 任务以获取命令sh -l
和参数/dir "%HOME%"
。那么cmder 将始终默认启动Git Bash,而不是微软的cmd shell。