简体   繁体   English

无法配置 git,缺少 .gitconfig 文件

[英]Can't configure git, missing .gitconfig file

when I try to config Git I receive the following error:当我尝试配置 Git 时,我收到以下错误:

$ git config --global user.name "John Smith"
error: could not lock config file /Users/John/.gitconfig: No such file or directory

My root directory is completely missing a .gitconfig file.我的根目录完全缺少.gitconfig文件。 When I try to make a new one I receive this error:当我尝试制作一个新的时,我收到此错误:

$ touch ~/.gitconfig
touch: /Users/John/.gitconfig: No such file or directory

My git's location:我的 git 的位置:

$ which git
/usr/local/git/bin/git

I've tried reinstalling Git several times (running OSX Yosemite) and I'm still having the same issue.我试过多次重新安装 Git(运行 OSX Yosemite),但我仍然遇到同样的问题。 I also cannot locate any .gitconfig.lock files, as mentioned in some posts regarding this issue.我也找不到任何 .gitconfig.lock 文件,如有关此问题的一些帖子中所述。

So I ended up solving this issue by reading the Customizing Git section of the documentation.所以我最终通过阅读文档的自定义 Git部分解决了这个问题。


While I could not touch a new .gitconfig file in my root directory as stated above, I read that the first place Git looks for configuration values is in etc/gitconfig (note the lack of a . in the name).虽然我无法touch.gitconfig在我的根目录文件如上所述,我读的第一Git会查找的配置值是在etc/gitconfig (注意缺少的.在名称)。

So I created a file called gitconfig inside of the etc directory and filled it in with a sample gitconfig I found online, and added my user information to the top like so:因此,我在etc目录中创建了一个名为gitconfig的文件,并使用我在网上找到的示例gitconfig填充它,并将我的user信息添加到顶部,如下所示:

[user]
  name = John Smith
  email = jsmith@example.com

I was then able to commit as my usual self, however I still don't have a .gitconfig in my root, so I am unable to config Git using git config --global , and must do the configurations manually in etc/gitconfig .然后我可以像往常一样提交,但是我的根目录中仍然没有.gitconfig ,所以我无法使用git config --global配置 Git,并且必须在etc/gitconfig手动进行配置。

For me the .gitconfig file was missing.I tried reinstalling Git several times, however it din't help me.对我来说,.gitconfig 文件丢失了。我尝试重新安装 Git 几次,但它对我没有帮助。 I resolved the issue by performing the below steps.我通过执行以下步骤解决了这个问题。

  1. create a folder structure c:/dev/home if already not present.如果尚未存在,则创建一个文件夹结构 c:/dev/home。
  2. Open the Windows command prompt.打开 Windows 命令提示符。 (Run as administrator) (以管理员身份运行)
  3. From the Windows command prompt, run the command "git init"在 Windows 命令提示符下,运行命令“git init”
  4. Run the following command: git config --global user.name "Example"运行以下命令: git config --global user.name "Example"
  5. Run the following command: git config --global user.email "Example@gmail.com"运行以下命令: git config --global user.email "Example@gmail.com"

The above steps will create the .gitconfig file in the path c:/dev/home and you will be able to set your desired username and email id.上述步骤将在路径 c:/dev/home 中创建 .gitconfig 文件,您将能够设置所需的用户名和电子邮件 ID。

On Windows systems, Git looks for the .gitconfig file in the $HOME directory (C:\\Users\\$USER for most people).在 Windows 系统上,Git 在 $HOME 目录(对于大多数人为 C:\\Users\\$USER)中查找 .gitconfig 文件。 So copy the file created in the above step to your Home directory by providing the required permission.因此,通过提供所需的权限,将上述步骤中创建的文件复制到您的主目录。

I solved that.我解决了那个。 By adding .gitconfig file to the Home directory.通过将 .gitconfig 文件添加到主目录。 Now it works fine.现在它工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM