git linux中.gitconfig文件的路径应该是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37554391/
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
What should be the path of .gitconfig file in linux?
提问by Sami
Hello can anyone tell me where the .gitconfig file reside, i mean what is the folder where this file should be stored. I am seeing the linux kernel tutorials from KernelNewbies at stuck where that file should reside. I am following this link http://kernelnewbies.org/FirstKernelPatchand under the heading setup git they tell me to make .gitconfig file now i dont know what should be the path.
你好,谁能告诉我 .gitconfig 文件所在的位置,我的意思是应该存储这个文件的文件夹是什么。我在 KernelNewbies 的 linux 内核教程中看到了该文件应驻留的位置。我正在关注此链接http://kernelnewbies.org/FirstKernelPatch,在标题 setup git 下,他们告诉我制作 .gitconfig 文件,现在我不知道路径应该是什么。
回答by amacrobert
Your global git configuration is written to ~/.gitconfig
.
您的全局 git 配置将写入~/.gitconfig
.
To override git configuration on a per-project basis, write to path/to/project/.git/config
.
要在每个项目的基础上覆盖 git 配置,请写入path/to/project/.git/config
.
However, you don't have to edit configuration files directly. You can set global or local configuration variables on the command line. For example, to set the global user name, use git config --global user.name "your-username"
.
但是,您不必直接编辑配置文件。您可以在命令行上设置全局或本地配置变量。例如,要设置全局用户名,请使用git config --global user.name "your-username"
.
回答by torek
There are three (or if you count --file
, even four) places you can configure Git:
您可以在三个(或者如果数一数--file
,甚至四个)地方配置 Git:
- At the machine level:
--system
. Unless you are the system administrator, you do not want to use this one. - At the user-specific level:
--global
. This is the one you want here. - At the repository level:
--local
, or without any--whatever
flag at all.
- 在机器级别:
--system
. 除非你是系统管理员,否则你不想使用这个。 - 在用户特定级别:
--global
. 这是你想要的。 - 在存储库级别:
--local
,或者根本没有任何标志。--whatever
The actual location of the user-specific file varies: the most common place is your home directory (~
or $HOME
) but there is this obnoxious XDG_HOME
thing, and this other obnoxious thing called Windows :-) , that can mess with this. So an easy way to avoid having to know where the file lives is to use git config --global
to set things.
特定于用户的文件的实际位置各不相同:最常见的位置是您的主目录 (~
或$HOME
),但有一个令人讨厌的XDG_HOME
东西,还有另一个令人讨厌的东西,称为 Windows :-) ,可能会与此混淆。因此,避免必须知道文件所在位置的简单方法是使用git config --global
设置内容。
My recommendation is to use git config --global core.editor name of your favorite editor
first, then to use git config --edit
to make sure that this actually works. For instance, if you prefer vim, run git config --global core.editor vim
. If you prefer nano, run git config --global core.editor nano
. If you like Emacs, or Notepad, or whatever, well, the pattern should be clear by now. :-)
我的建议是先使用,然后使用以确保这确实有效。例如,如果您更喜欢 vim,请运行. 如果您更喜欢 nano,请运行. 如果您喜欢 Emacs、记事本或其他任何东西,那么现在模式应该很清楚了。:-)git config --global core.editor name of your favorite editor
git config --edit
git config --global core.editor vim
git config --global core.editor nano
Once you have set your core.editor
, using --edit
will make sure it really works, and you will be able to see the format for the settings file (it's basically an INI-style file). Make sure that whatever editor you use, it writes text files as ASCII if possible, or UTF-8 when needing auxiliary non-ASCII characters, not "RichText" and not UTF-16, and without using a pointless byte-order mark ("BOM"), as these will give Git heartburn.
一旦你设置了你的core.editor
, using--edit
将确保它真的有效,你将能够看到设置文件的格式(它基本上是一个 INI 样式的文件)。确保无论您使用什么编辑器,它都会尽可能将文本文件写入 ASCII,或者在需要辅助非 ASCII 字符时将文本文件写入 UTF-8,而不是“RichText”和 UTF-16,并且不使用无意义的字节顺序标记 (" BOM"),因为这些会让 Git 胃灼热。
Besides core.editor
(which you do not have to set, I just recommend it), you mustset:
此外core.editor
(您不必设置,我只是推荐它),您必须设置:
user.name "your name"
user.email [email protected]
user.name "your name"
user.email [email protected]
and you probably shouldset:
你可能应该设置:
core.pager "less -S"
color.branch auto
color.diff auto
diff.renames true
(or even tocopy
)diff.renameLimit 0
merge.conflictstyle diff3
core.pager "less -S"
color.branch auto
color.diff auto
diff.renames true
(甚至到copy
)diff.renameLimit 0
merge.conflictstyle diff3
although all of these are matters of taste.
虽然所有这些都是品味问题。
Once you have your core.editor
set, you can set these others with git config --global var.iable"value"
, or with git config --global --edit
. The quotes here are needed only if the value
is more than one word (contains whitespace) or needs other protection from the shell (has $
or *
characters in it, for instance). (And: using --edit
is particularly valuable when you have set something long and complicated, like an alias, and want to fix a small typo, or experiment, without having to re-enter the whole thing.)
一旦你有你的core.editor
设置,可以设置这些人有,或者用。这里的引号只用在超过一个字(包含空格),或从shell需要其他的保护(有或人物在里面,例如)。(并且:当您设置了一些又长又复杂的东西时,使用特别有价值,比如别名,并且想要修复一个小的错字或实验,而不必重新输入整个东西。)git config --global var.iable"value"
git config --global --edit
value
$
*
--edit