git 找不到 gitconfig 文件

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

Cannot find gitconfig file

gitlinux-mint

提问by elnurcoot

I just started learning about Linux and Git. Im using Linux Mint. I have Git and emacs installed via apt-get.

我刚刚开始学习 Linux 和 Git。我使用 Linux Mint。我通过 apt-get 安装了 Git 和 emacs。

Im using the following tutorial https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup

我使用以下教程 https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup

it says that there are configuration files in three different places:

它说在三个不同的地方有配置文件:

  1. /etc/gitconfigfile
  2. ~/.gitconfigor ~/.config/git/configfile
  3. config file in the Git directory (that is, .git/config) of whatever repository you're currently using.
  1. /etc/gitconfig文件
  2. ~/.gitconfig~/.config/git/config档案
  3. 您当前使用的任何存储库的 Git 目录(即 .git/config)中的 config 文件。

I have just started with Git so assume that option 3) is not applicable

我刚刚开始使用 Git,所以假设选项 3) 不适用

I checked both 1) and 2) - i just cannot locate the files anywhere

我检查了 1) 和 2) - 我只是无法在任何地方找到文件

I googled this with no luck and did sudo find . -namein the root directory

我在没有运气的情况下用谷歌搜索了这个并sudo find . -name在根目录中做了

Have no clue what is happening as when i run this

不知道当我运行这个时发生了什么

$ git config --global user.name "John Doe"
$ git config --global user.email [email protected]

(i used my name surname above obviously)

(我显然在上面使用了我的名字姓氏)

it doesn't give me an error or anything - so where does it write this config data then?? where are these files?

它没有给我一个错误或任何东西 - 那么它在哪里写这个配置数据呢??这些文件在哪里?

采纳答案by VonC

As confirmed by the OP, any git config --globalcommand will create/update ~/.gitconfig.

正如 OP 所确认的那样,任何git config --global命令都将 create/update ~/.gitconfig

But as it is an hidden file by default, you would need a ls -alrtto see it.
git config --global -lwill list its content.

但由于默认情况下它是一个隐藏文件,您需要ls -alrt查看它。
git config --global -l将列出其内容。

More generally, git config --list --show-originshows all config files (and each line of the config data).
With Git 2.26 (Q1 2020), you can add a --show-scopeoption

更一般地,git config --list --show-origin显示所有配置文件(以及配置数据的每一行)。
使用 Git 2.26(2020 年第一季度),您可以添加一个--show-scope选项

git config --list --show-origin --show-scope

That will also print the scope ("local", "global", etc) of all displayed config values.

这还将打印所有显示的配置值的范围(“ local”、“ global”等)。

回答by BinaryJoe01

To find your global .gitconfigfile:

要查找您的全局.gitconfig文件:

  1. Open your terminal or command prompt
  2. Go to your root directory by typing cd ~
  3. Once in your root folder type ls -alrt
  4. You will see a .gitconfigfile
    • To open your .gitconfigfile type open .gitconfig
  1. 打开终端或命令提示符
  2. 通过键入转到您的根目录 cd ~
  3. 一旦进入您的根文件夹类型 ls -alrt
  4. 你会看到一个.gitconfig文件
    • 打开您的.gitconfig文件类型open .gitconfig

To find a particular repository's .gitconfigfile:

要查找特定存储库的.gitconfig文件:

  1. Open your terminal or command prompt
  2. Go to your repository'sroot directory by typing cd path/to/repository-directory
  3. Once in your repository's root directory type ls -alrt
  4. You will see a .gitdirectory. Type cd .git
  5. Once in your repository's gitdirectory type ls -alrt
  6. You will see a configfile
    • To open your repository's .gitconfigfile type open config
  1. 打开终端或命令提示符
  2. 通过键入转到存储库的根目录cd path/to/repository-directory
  3. 一旦进入存储库的根目录类型 ls -alrt
  4. 你会看到一个.git目录。类型cd .git
  5. 一旦进入存储库的git目录类型ls -alrt
  6. 你会看到一个config文件
    • 打开存储库的.gitconfig文件类型open config

回答by Help Out

I got my config file by using git config --system --list

我通过使用获得了我的配置文件 git config --system --list