bash 无法配置 git,缺少 .gitconfig 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28143027/
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
Can't configure git, missing .gitconfig file
提问by garythegoat
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. When I try to make a new one I receive this error:
我的根目录完全缺少一个.gitconfig
文件。当我尝试制作一个新的时,我收到此错误:
$ 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. I also cannot locate any .gitconfig.lock files, as mentioned in some posts regarding this issue.
我试过多次重新安装 Git(运行 OSX Yosemite),但我仍然遇到同样的问题。我也找不到任何 .gitconfig.lock 文件,如有关此问题的一些帖子中所述。
回答by garythegoat
So I ended up solving this issue by reading the Customizing Gitsection 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
(注意.
名称中缺少 a )。
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:
所以我创建了一个名为gitconfig
insideetc
目录的文件,并用gitconfig
我在网上找到的示例填充它,并将我的user
信息添加到顶部,如下所示:
[user]
name = John Smith
email = [email protected]
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 git config --global
,并且必须在etc/gitconfig
.
回答by M.Saha
For me the .gitconfig file was missing.I tried reinstalling Git several times, however it din't help me. I resolved the issue by performing the below steps.
对我来说,.gitconfig 文件丢失了。我尝试重新安装 Git 几次,但它对我没有帮助。我通过执行以下步骤解决了这个问题。
- create a folder structure c:/dev/home if already not present.
- Open the Windows command prompt. (Run as administrator)
- From the Windows command prompt, run the command "git init"
- Run the following command: git config --global user.name "Example"
- Run the following command: git config --global user.email "[email protected]"
- 如果尚未存在,则创建一个文件夹结构 c:/dev/home。
- 打开 Windows 命令提示符。(以管理员身份运行)
- 在 Windows 命令提示符下,运行命令“git init”
- 运行以下命令: git config --global user.name "Example"
- 运行以下命令: git config --global user.email "[email protected]"
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). So copy the file created in the above step to your Home directory by providing the required permission.
在 Windows 系统上,Git 在 $HOME 目录(对于大多数人为 C:\Users\$USER)中查找 .gitconfig 文件。因此,通过提供所需的权限,将在上述步骤中创建的文件复制到您的主目录。