致命:无法访问“H:\/.config/git/config”:参数无效 [Windows 7 上的 Git]

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22736191/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 17:56:50  来源:igfitidea点击:

fatal: unable to access 'H:\/.config/git/config': Invalid argument [Git on Windows 7]

gitwindows-7

提问by Exocomp

I get this error when opening a git repository:

打开 git 存储库时出现此错误:

fatal: unable to access 'H:/.config/git/config': Invalid argument

致命:无法访问“H:/.config/git/config”:参数无效

Where in git is this path being pulled from?

在 git 中,这条路径是从哪里拉出来的?

'H:/.config/git/config'

'H:/.config/git/config'

I found some articles that it might be the "Home" or "UserProfile" environment variables but in my case the "Home" variable is not created and the "UserProfile" is not pointing to that path. So where is git getting that path from?

我发现一些文章可能是“Home”或“UserProfile”环境变量,但在我的情况下,“Home”变量未创建,“UserProfile”未指向该路径。那么 git 是从哪里得到这条路径的呢?

回答by JK Dennis

I experienced a similar issue when not connected to my work network via VPN. Running the following from a command window worked for me:

未通过 VPN 连接到我的工作网络时,我遇到了类似的问题。从命令窗口运行以下对我有用:

net use H: /delete

This command actually deleted the H drive. If you actually use the mapped drive that is causing the issue, then this way could cause you other problems that would only be solved by remapping the drive (net use H:, followed by the mapped drive path). As a note, I did delete the HOME% variables (using "set HOME=" from the command line), but it did work until the command above was run.

这个命令实际上删除了H盘。如果您实际上使用了导致问题的映射驱动器,那么这种方式可能会导致其他问题,这些问题只能通过重新映射驱动器来解决(净使用 H:,然后是映射驱动器路径)。请注意,我确实删除了 HOME% 变量(使用命令行中的“set HOME=”),但在运行上述命令之前它确实有效。

回答by Canhua Li

net delete is not a must.

net delete 不是必须的。

First check HOME setting, then change HOME and HOMEDRIVE to a existing dir.

首先检查 HOME 设置,然后将 HOME 和 HOMEDRIVE 更改为现有目录。

c:\git\selenium-automation>set HOME
HOME=U:\
HOMEDRIVE=U:
HOMEPATH=\
HOMESHARE=\XX

then change HOME and HOMEDRIVE by

然后通过以下方式更改 HOME 和 HOMEDRIVE

set HOME=c:\tmp
set HOMEDRIVE=C:

c:\git\selenium-automation>set HOME

c:\git\selenium-automation>set HOME

HOME=c:\tmp
HOMEDRIVE=c:
HOMEPATH=\
HOMESHARE=\XX

回答by Hani

A lot of solutions were presented. Conclusion: The problem is a remote HOMEPATH and HOMEDRIVE environmental variable and appears when you are not connected to your network.

提出了很多解决方案。结论:问题是远程 HOMEPATH 和 HOMEDRIVE 环境变量,并且在您未连接到网络时出现。

IMHO the solution with no side-effects(when your HOME variable is not set) is setting your HOME environmental variable of your profile to an existing localpath.

恕我直言,没有副作用的解决方案(当您的 HOME 变量未设置时)将您的配置文件的 HOME 环境变量设置为现有的本地路径。

First check if HOME is set or not. Open cmd.exe (Command prompt) and type

首先检查是否设置了 HOME。打开 cmd.exe(命令提示符)并输入

set HOME

If you do not get a result, just for HOMEPATH and HOMEDRIVE, than HOME is NOT set. Go to control panel:

如果您没有得到结果,仅针对 HOMEPATH 和 HOMEDRIVE,则未设置 HOME。进入控制面板:

Press WIN-R and then type control. Go to users profiles and you find a link on the left sidebar to change the environmental variable of your profile. The rest should be self-explanatory. Add variable HOMEwith path e.g. c:\users\myprofile.

按 WIN-R,然后键入control。转到用户配置文件,您会在左侧边栏上找到一个链接来更改配置文件的环境变量。其余的应该是不言自明的。添加HOME带有路径的变量,例如c:\users\myprofile.

With this attempt you could let HOMEPATH and HOMEDRIVE untouched and get no side-effects when reconnected to your network.

通过这种尝试,您可以让 HOMEPATH 和 HOMEDRIVE 保持不变,并且在重新连接到网络时不会产生副作用。

Worked for me.

对我来说有效。

IMPORTANT:But you lose your git settings. So you have to copy at least .gitconfigfrom your remote network home drive to your new local HOME directory before you disconnect from your network.

重要提示:但是您丢失了 git 设置。因此,在.gitconfig断开网络连接之前,您必须至少从远程网络主驱动器复制到新的本地主目录。

Thanks to Navjot Bhardwaj and VonC.

感谢 Navjot Bhardwaj 和 VonC。

回答by AlexPes

Set HOME var in 'User variable for ' (Control Panel\All Control Panel Items\System\ => Advanced system settings\Advanced\Env variables)

在“用户变量”中设置 HOME 变量(控制面板\所有控制面板项\系统\ => 高级系统设置\高级\环境变量)

It resolved my issue.

它解决了我的问题。

回答by VonC

Make sure, in a command line window:

确保在命令行窗口中:

  • HOMEis indeed not set: type set HOME, which would return its value if any
  • the issue persists with the latest msysgit distribution(1.9.0): unzip that archive anywhere, and call git with its full path:

    c/mydir/PortableGit-1.9.0-preview20140217/bin/git.exe --global -l
    
  • HOME确实没有设置: type set HOME,如果有,它将返回其值
  • 问题在最新的 msysgit 发行版(1.9.0)中仍然存在:在任何地方解压缩该存档,并使用其完整路径调用 git:

    c/mydir/PortableGit-1.9.0-preview20140217/bin/git.exe --global -l
    

回答by Navjot Bhardwaj

If you'll check your GIT installation path /git/etc/profile you'll see HOME variable set as:
HOME="$HOMEDRIVE$HOMEPATH"

For this I created HOME variable in my Environment variables and it started working.

如果你检查你的 GIT 安装路径 /git/etc/profile,你会看到 HOME 变量设置为:
HOME="$HOMEDRIVE$HOMEPATH"

为此,我在我的环境变量中创建了 HOME 变量,它开始工作。

回答by Roman

My situation was that I ran git checkout <branch>and I had fatal: unable to access 'H://.gitconfig': Invalid argument. Then I run set HOMEand had no results. The following steps solved the issue

我的情况是我跑了git checkout <branch>,我有fatal: unable to access 'H://.gitconfig': Invalid argument。然后我跑了set HOME,没有结果。以下步骤解决了问题

  1. change SSH keys
  2. restart the computer
  3. find .gitconfig (should be in the root of H:// or whatever drive name you have)
  4. open it with Notepad++ (or other editor) and save as is. If it is empty, then save empty one
  5. then git checkout masterstarted working
  1. 更改 SSH 密钥
  2. 重新启动计算机
  3. 找到 .gitconfig(应该在 H:// 的根目录或您拥有的任何驱动器名称中)
  4. 用 Notepad++(或其他编辑器)打开它并按原样保存。如果它是空的,那么保存一个空的
  5. 然后git checkout master开始工作

If it happned once again, I would start from step 3 :-)

如果它再次发生,我会从第 3 步开始:-)

回答by jimmy

As some people are saying this seems to be an issue with HomeDrive and HomePath when using network drives.

正如一些人所说,这似乎是使用网络驱动器时 HomeDrive 和 HomePath 的问题。

For me this was solved by running my git commands as admin.

对我来说,这是通过以管理员身份运行我的 git 命令来解决的。