我想经常运行一个 powershell 脚本来自动推送到 git。
我为 Windows 安装了 GitHub。如果我运行“Git Shell”,则会打开一个 powershell shell,但它安装了 git
功能并在 C:\Users\crclayton\Desktop\GitHub>
中启动,而不是在 H:\>
如果我尝试在普通 PowerShell 中使用 git
,它会告诉我 git 未被识别为函数。但是,如果我在普通 powershell 中加载脚本 C:\Users\crclayton\AppData\Local\GitHub\shell.ps1
,我可以使用 git
,但是当我导航到文件夹并尝试 add
或 commit
或 push
,我收到错误:
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
任何人都可以看出问题所在或提出替代方案吗?提前致谢。
最佳答案
如果您想在 powershell 脚本中使用 git 命令,请确保您在环境变量“路径”中有一条记录,其中包含 git 的实际路径。 在我的例子中,它看起来如所附图片所示!:
无论如何,这个设置是在我安装 Git Extensions 时自动添加的。如果您不使用扩展,只需手动或从 powershell 脚本将此行添加到“Path”变量 eather。
希望对你有帮助
关于git - 尝试使用 powershell 提交到 GitHub 导致错误 "fatal: unable to access ' Microsoft.PowerShell.Core\FileSystem",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28685935/