Trying to commit to GitHub using powershell results in error “fatal: unable to access 'Microsoft.PowerShell.Core\FileSystem”
我想运行一个powershell脚本来经常自动将其推送到git。
我为Windows安装了GitHub。如果我运行" Git Shell",则会打开一个Powershell外壳,但它安装了
中启动
如果我尝试在普通的PowerShell中使用
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
这是我的代码:
1 2 3 4 5 6 7 8 9 | #(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 |
任何人都可以看到问题所在或提出替代建议吗?预先感谢。
如果要在Powershell脚本中使用git命令,请确保在环境变量\\'Path \\'中有一条记录,其中包含git的实际路径。
就我而言,它看起来如所附图片所示:
无论如何,此设置是在我安装Git Extensions时自动添加的。如果不使用扩展名,只需手动或通过powershell脚本将此行添加到\\'Path \\'变量中即可。
希望这会有所帮助
用于Windows的Github使用
Verify execution of scripts is allowed with
Get-ExecutionPolicy (should beRemoteSigned orUnrestricted ). If scripts are not enabled, run PowerShell as Administrator and callSet-ExecutionPolicy RemoteSigned -Scope CurrentUser -Confirm .