无法使用我的 GitHub 帐户错误设置 git:无法锁定配置文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14959972/
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 15:32:27  来源:igfitidea点击:

Trouble setting up git with my GitHub Account error: could not lock config file

git

提问by codepros

I'm getting this error when trying to set the global config:

尝试设置全局配置时出现此错误:

$ git config --global user.name "Your Name Here"
error: could not lock config file /pathto/file/.gitconfig: No such file or directory

and the file .gitconfig is already exists, anyone have any ideas??

并且文件 .gitconfig 已经存在,有人有任何想法吗??

采纳答案by VonC

A bit like in "Trouble setting up Tower with my GitHub Account - error: could not lock config file", check how that ~/.gitconfigfile has been created.
Ie: with which rights associated to it?

有点像“使用我的 GitHub 帐户设置 Tower 时遇到问题 - 错误:无法锁定配置文件”,请检查该~/.gitconfig文件是如何创建的。
即:与哪些权利相关联?

Make also sure your $HOMEvariable is correctly set when you are executing the git config --globalcommand.

还要确保在$HOME执行git config --global命令时正确设置了变量。

回答by przemek

Check if you have a .git directory in your home folder and if you don't:

检查您的主文件夹中是否有 .git 目录,如果没有:

mkdir ~/.git

mkdir ~/.git

Solved the problem in my case.

解决了我的问题。

回答by Andrew Cassidy

I've gotten this error when a lock file exists for gitconfig. Try and find and remove .gitconfig.lock (on my linux box it was in my home dir)

当 gitconfig 存在锁定文件时,我收到此错误。尝试查找并删除 .gitconfig.lock (在我的 linux 机器上,它位于我的主目录中)

回答by praveen

just do Run as Administrator.......you need to run the program in the run as administrator mode in windows

只需以管理员身份运行.......您需要在Windows中以管理员身份运行模式运行该程序

回答by paperclip

Windows Users: Ensure your Environment Variables are correctly setup.

Windows 用户:确保您的环境变量设置正确。

I had the following for my account username 'paperclip':

我的帐户用户名“回形针”有以下内容:

My Computer (right-click) > Properties > Advanced (tab) > Environment Variables (under System Variables):

My Computer (right-click) > Properties > Advanced (tab) > Environment Variables (under System Variables)

HOME -> %HOMEPATH%

HOME -> %HOMEPATH%

HOMEPATH -> C:\Documents and Settings\paperclip

HOMEPATH -> C:\Documents and Settings\paperclip

It seems like Git could not resolve / expand %HOME%to %HOMEPATH%as you would it expect it to. Instead I needed to make %HOME%the same as %HOMEPATH%by changing it to:

这似乎是Git的无法解析/扩展%HOME%%HOMEPATH%,你会它,它期望。相反,我需要做%HOME%的一样%HOMEPATH%,改成:

HOME -> C:\Documents and Settings\paperclip

HOME -> C:\Documents and Settings\paperclip

回答by savelich

In Windows: Right click on "Git Bash" icon -> Run as Administrator. it helped me.

在 Windows 中:右键单击“Git Bash”图标 -> 以管理员身份运行。它帮助了我。

Git tries to create a config file on disk C:/ but it has no permission to do that.

Git 尝试在磁盘 C:/ 上创建一个配置文件,但它没有这样做的权限。

回答by Arnis Juraga

This will happen, if the user home directory is not writable by the user. git config --globalneeds to create a "lock" file (~/.gitconfig.lock) in user home directory.

如果用户无法写入用户主目录,就会发生这种情况。 git config --global需要~/.gitconfig.lock在用户主目录中创建一个“锁定”文件 ( )。

Check the permissions and try to create one.

检查权限并尝试创建一个。

# cat ~/.gitconfig.lock
cat: /home/users/developer/.gitconfig.lock: No such file or directory
# touch ~/.gitconfig.lock

## Now check, if a file has been created?
# cat ~/.gitconfig.lock
#

NOTE:If it succeeds, You must delete this file, otherwise git will throw another error!

注意:如果成功,你必须删除这个文件,否则 git 会抛出另一个错误!

If a user has no permission of creating this file, You must check and change permissions for the home directory.

如果用户没有创建此文件的权限,您必须检查和更改主目录的权限。

回答by Joseph Tingiris

This could be caused by the presence of ~/.gitconfig.lock It's possible this file could be an artifact of a previously running git that was aborted for some reason, e.g. ansible timed out or ^C

这可能是由 ~/.gitconfig.lock 的存在引起的。这个文件可能是以前运行的 git 的工件,由于某种原因被中止,例如 ansible 超时或 ^C

回答by Paul Liu

Just use the following command if you wanna set configuration in system level:

如果要在系统级别设置配置,只需使用以下命令:

$ sudo git config --system user.name "my_name"

回答by René Nyffenegger

I have "experienced" this error on Windows because my name (and hence %HOMEPATH%) contains a non ascii character (é). Either git or cmd.exe or anything else could not cope with this.

我在 Windows 上“经历过”这个错误,因为我的名字(因此%HOMEPATH%)包含一个非 ascii 字符(é)。git 或 cmd.exe 或其他任何东西都无法解决这个问题。