git - 尝试使用 powershell 提交到 GitHub 导致错误 "fatal: unable to access ' Microsoft.PowerShell.Core\FileSystem"

标签 git powershell github windows-7 github-for-windows

我想经常运行一个 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,但是当我导航到文件夹并尝试 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

任何人都可以看出问题所在或提出替代方案吗?提前致谢。

最佳答案

如果您想在 powershell 脚本中使用 git 命令,请确保您在环境变量“路径”中有一条记录,其中包含 git 的实际路径。 在我的例子中,它看起来如所附图片所示!:

Path environment variable

无论如何,这个设置是在我安装 Git Extensions 时自动添加的。如果您不使用扩展,只需手动或从 powershell 脚本将此行添加到“Path”变量 eather。

希望对你有帮助

关于git - 尝试使用 powershell 提交到 GitHub 导致错误 "fatal: unable to access ' Microsoft.PowerShell.Core\FileSystem",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28685935/

相关文章:

windows - Windows 版 Git-scm、msysGit 和 Git 之间的差异

git - 修复损坏的 git 仓库——如何重新开始

git - 在 Tomcat 上设置远程 Git 仓库

git - 如何列出特定提交后的提交?

string - 如何将 cmdlet 插入到 powershell 中的字符串中

c# - 将 httpwebresponse 写入文件——powershell——简短而甜美(管道)

exception - Powershell 捕获异常

Git 克隆错误

git - 防止其他人强制推送到我的 Git 存储库

github - 有没有办法搜索github Wiki页面?