windows 退出 git 控制台:如何执行批处理文件然后返回到 git 控制台?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11865085/
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
Out of a git console: how do I execute a batch file and then return to git console?
提问by eckes
I have a small utility script called clear.bat
that does some housekeeping work on my sources.
我有一个名为的小实用程序脚本clear.bat
,它对我的资源进行一些整理工作。
It is a .bat
file so that I could easily double-click it in Windows Explorer.
这是一个.bat
文件,因此我可以轻松地在 Windows 资源管理器中双击它。
Sometimes, I find it more handy to execute it from my Git bash (msysgit, if this matters).
有时,我发现从我的 Git bash(msysgit,如果这很重要)执行它更方便。
To do this, I type
为此,我输入
cmd
clear.bat
exit
cmd
turns my Git bash into a normal cmd
window where I could easily execute my batch. When I type exit
, the cmd
environment is terminated and I'm back in my Git bash.
cmd
将我的 Git bash 变成一个普通cmd
窗口,在那里我可以轻松地执行我的批处理。当我输入 时exit
,cmd
环境终止,我又回到了我的 Git bash 中。
Could this be achieved in an easier way?
这可以以更简单的方式实现吗?
I tried cmd /C clean.bat
since the docssay
我试过,cmd /C clean.bat
因为文档说
Syntax
CMD [charset] [options]
CMD [charset] [options] [/c Command]
CMD [charset] [options] [/k Command]
Options
/C Run Command and then terminate
/K Run Command and then return to the CMD prompt.
This is useful for testing, to examine variables
Edit:
Just noticed that the post is broken.
编辑:
刚刚注意到该帖子已损坏。
What I want is to execute clean.bat
from within the Git bash without having to type the three commands above (cmd
, clear.bat
, exit
). I just want to execute the .bat
file from within my Git bash. Obvious way would be to create a separate .sh
file that does the same work but this will lead to double code.
我想要的是clean.bat
从 Git bash 中执行而不必键入上面的三个命令 ( cmd
, clear.bat
, exit
)。我只想.bat
从我的 Git bash 中执行该文件。明显的方法是创建一个单独的.sh
文件来完成相同的工作,但这会导致双重代码。
Edit 2:When I execute cmd /C clean.bat
, the Git bash turns into a plain CMD environment and only displays the prompt. The file clean.bat
does not get executed. It's the same as if I just type cmd
.
编辑 2:当我执行时cmd /C clean.bat
,Git bash 变成一个普通的 CMD 环境并且只显示提示。该文件clean.bat
不会被执行。就好像我只是输入一样cmd
。
Also, adding a /debug
switch does literally nothing. Seems like only cmd
gets evaluated and all further parameters are getting ignored.
此外,添加/debug
开关实际上没有任何作用。似乎只cmd
得到评估,所有进一步的参数都被忽略了。
回答by eckes
After playing around a bit more, I found the solution myself:
玩了一会儿之后,我自己找到了解决方案:
cmd "/C clean.bat"
does the trick. But I got no clue, why...
诀窍。但我不知道为什么...
回答by half-potato
./clear.bat
will do the trick.
./clear.bat
会做的伎俩。
回答by Yitzhak Steinmetz
The Git for Windows(msysGit has been superseded by Git for Windows1) FAQsays you have 3 options:
该混帐的Windows(msysGit已经通过GIT中的Windows取代1)常见问题解答说,你有3种选择:
Run programs that have problems using the
winpty
utility. This allows you to keep using the nicer mintty terminal, but can become unwieldy if you need the workaround for many programs.Modify the shortcut for Git Bash to run
bash
directly withoutmintty
so it uses the default console host and configure it for "Quick Edit", reasonable size and scroll-back and suitable unicode font. You'll still have to live with the other quirks of console host.Install and use ConEmu.
回答by lav
I like start clean
, it opens a new window with cmd. This method has some benefits:
我喜欢start clean
,它用 cmd 打开一个新窗口。这种方法有一些好处:
- cmd.exe gets a native console
- the new console has a native windows character encoding (e.g. cp1251 vs utf8)
- cmd.exe 获取本地控制台
- 新控制台具有原生 Windows 字符编码(例如 cp1251 与 utf8)