2015-02-24 144 views
1

我想运行一个PowerShell脚本自动推送到GIT每隔一段时间。尝试提交到GitHub使用PowerShell导致错误“致命:无法访问'Microsoft.PowerShell.Core FileSystem”

我为Windows安装了GitHub。如果我运行“混帐壳牌”,PowerShell的外壳打开,但它的功能安装gitC:\Users\crclayton\Desktop\GitHub>开始不H:\>

如果我尝试在一个正常的PowerShell来使用git,它告诉我的git没有被识别为一个函数。但是,如果我在正常的PowerShell加载脚本C:\Users\crclayton\AppData\Local\GitHub\shell.ps1,我可以使用git,但是,当我浏览到该文件夹​​,并尝试addcommitpush,我得到的错误:

git.exe : fatal: unable to access

'Microsoft.PowerShell.Core\FileSystem::\mypath../.config/git/config': Invalid argument At

C:\Users\crclayton\Desktop\autogit.ps1:7 char:4

  • git <<<< add *

  • CategoryInfo : NotSpecified: (fatal: unable t...nvalid argument: String) [], RemoteException

  • FullyQualifiedErrorId : NativeCommandError

这是我的代码:

#(Resolve-Path "$env:LOCALAPPDATA\GitHub\shell.ps1") # tried this, doesn't work 
C:\Users\crclayton\AppData\Local\GitHub\shell.ps1 

$msg = Read-Host "Enter commit msg" 

cd "C:\Users\crclayton\project\" 
git add * 
git commit -a -m $msg 
git push origin master 

任何人都可以看到有什么问题或建议替代?提前致谢。

回答

2

如果你想使用PowerShell脚本里面Git命令请确保您有与实际路径git的环境变量“路径”的记录。 对我来说,它看起来附加的图片,如图!:

Path environment variable

无论如何,当我安装了Git的扩展自动添加此设置。如果您不使用扩展,只需手动或从PowerShell脚本将此行添加到'Path'变量eather。

希望这会有所帮助

+0

谢谢!这工作,但只有当我发现'git.exe'埋在以下文件夹:'C:\ Users \ crclayton \ AppData \ Local \ GitHub \ PortableGit_c2ba306e536fdf878271f7fe636a147ff37326ad \ bin'。 – 2015-03-11 23:12:56

1

Github for windows使用posh-git所以你可能想确认你是following the manual install被powershell使用。

Verify execution of scripts is allowed with Get-ExecutionPolicy (should be RemoteSigned or Unrestricted). If scripts are not enabled, run PowerShell as Administrator and call Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Confirm .

相关问题