跑在git的外壳批处理文件 [英] Running a batch file in git shell

查看:141
本文介绍了跑在git的外壳批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows 7下我有一些检查回购的状态和输出返回到文件的批处理文件(使用标准的PowerShell发出的Git命令)。

Under Windows 7 I have a batch file for checking the status of some repos and outputting the returns to a file (with standard powershell issued git commands).

从git的外壳启动时能正常工作,我的问题是不首先推出的git壳我该怎么做呢?

This works fine when launched from git shell, my question is how can I do this without launching git shell first?

所以,我希望能够在一个标准的提示输入或可运行的批处理文件中的命令/命令将在外壳的git推出一个给定的批处理文件。

So I want to be able to enter in a standard prompt or in a runnable batch file a command / commands which will launch a given batch file in git shell.

推荐答案

如果你考虑一下 混帐cmd.bat 做,所有你需要做的是设置正确的变量%PATH%之前在脚本的Git命令:

If you consider what git-cmd.bat does, all you need to do is to set the right variable %PATH% before your git commands in your script:

如果你不这样做,这里是您将看到:

If you don't, here is what you would see:

C:\Users\VonC>git --version
'git' is not recognized as an internal or external command,
operable program or batch file.

我已经uncom pressed的最新的便携式msysgit的版本

把任何地方 test.bat的脚本(所以没有涉及存在的PowerShell)具有以下内容:

Put anywhere a test.bat script (so no powershell involved there) with the following content:

@setlocal

@set git_install_root="C:\Users\VonC\prg\PortableGit-1.7.11-preview20120620"
@set PATH=%git_install_root%\bin;%git_install_root%\mingw\bin;%git_install_root%\cmd;%PATH%

@if not exist "%HOME%" @set HOME=%HOMEDRIVE%%HOMEPATH%
@if not exist "%HOME%" @set HOME=%USERPROFILE%

@set PLINK_PROTOCOL=ssh

REM here is the specific git commands of your script

git --version
echo %HOME%
git config --global --list

确认首页的设置是否正确,因为Git会找你的全球混帐配置那里。

Make sure HOME is correctly set, because Git will look for your global git config there.

结果会给你:

C:\Users\VonC>cd prog\git

C:\Users\VonC\prog\git>s.bat

C:\Users\VonC\prog\git>git --version
git version 1.7.11.msysgit.0

C:\Users\VonC\prog\git>echo C:\Users\VonC
C:\Users\VonC

C:\Users\VonC\prog\git>git config --global --list
user.name=VonC

请注意:同样的脚本将完全从PowerShell会话工作

Note: that same script would work perfectly from a powershell session.

这篇关于跑在git的外壳批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆