我如何执行批处理文件中的若干Git命令没有第一个命令后终止? [英] How do I execute several git commands in a batch file without terminating after the first command?
问题描述
我试图把一系列GIT的命令,我总是用不断togeter批处理文件,这样,我不重复自己太多。例如,我有 update_repo_branch.bat
称这个批处理文件更新本地回购和同步分支与远程分支:
I tried to put a series of GIT commands that I always use continuously togeter as batch files so that I don't repeat myself too much. For example, I have this batch file called update_repo_branch.bat
to update a local repo and synch a branch with the remote branch:
关闭@echo结果
如果(%1)==()转到结束结果
如果(%2)==()转到结束结果
CD%1结果
git的结帐%2结果
混帐取产地结果
混帐合并的ORing /%2结果
:结束
@echo off
if(%1) == () goto end
if(%2) == () goto end
cd %1
git checkout %2
git fetch origin
git merge oring/%2
:end
好偷懒,但我发现的是,当GIT命令结束时,它似乎发送一个出口标志回到终止任何正在运行即可。因此,使用一个批处理文件来exectute他们都一气呵成根本不起作用。不知道如何解决它?
Good to be lazy, but what I found is that when a GIT command is finished, it seems to send an exit flag back to terminate whatever is running. Therefore, using a batch file to exectute them all in one go simply doesn't work. Any idea how to work around it?
推荐答案
我不知道这是否是所有Windows的Git包真,但至少有一些使用 git.cmd
脚本各地实际的git可执行文件的包装(例如 git.exe
)。所以,当你的批处理文件使用混帐
命令时,Windows实际上是运行另一个批处理文件。
I'm not sure if this is true for all Windows git packages, but at least some use a git.cmd
script as a wrapper around the actual git executables (for example git.exe
). So when you're batch file uses a git
command, Windows is actually running another batch file.
不幸的是,当一个批处理文件调用另一个,默认情况下它跳到被调用批处理文件,再也没有回来(这是与古MS-DOS命令处理器或一些兼容性)。
Unfortunately, when one batch file invokes another, by default it 'jumps' to the invoked batch file, never to return (this is for compatibility with ancient MS-DOS command processors or something).
您可以用几种方法解决这个问题:
You can solve this problem in a couple ways:
-
调用使用
呼叫
命令来运行混帐
在您的批处理文件> git.cmd 批处理文件,并返回到你的:
invoke
git
in your batch files using thecall
command to run thegit.cmd
batch file and return back to yours:
call git checkout %2
call git fetch origin
rem etc...
调用混帐
中使用 .exe文件
扩展明确,以避免您的批处理文件中的 git.cmd
批处理文件。对于这个工作,你可能需要确保你有你的路径和设置方式与其他环境变量 git.exe
预期(这似乎是什么 git.cmd
确实在msysgit):
invoke git
in your batch file using the .exe
extension explicitly to avoid the git.cmd
batch file altogether. For this to work, you might need to make sure that you have your path and other environment variables set the way git.exe
expects (that seems to be what git.cmd
does in msysgit):
git.exe checkout %2
rem etc...
这篇关于我如何执行批处理文件中的若干Git命令没有第一个命令后终止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!