如果您想设置特定于特定存储库的配置,您有两种选择:从命令行进行配置,或在编辑器中编辑存储库的配置文件。
选项 1:通过命令行配置
只需使用命令行,cd
进入 Git 存储库的根目录,然后运行git config
, without the --system
和--global
flags,分别用于配置您的机器和用户 Git 设置:
cd <your-repo>
git config <setting-name> <setting-value>
git config <setting-name>=<setting-value> # alternate syntax
选项2:直接编辑配置文件
您的另一个选择是直接编辑存储库配置文件。对于默认的 Git 克隆,通常是.git/config
文件位于存储库的根文件夹中。只需在编辑器中打开该文件并开始添加您的设置,或者在命令行中使用它调用编辑器git config --edit
.
资源
您可以在以下位置了解有关配置 Git 的更多信息Linux 内核 Git 官方文档git config https://www.kernel.org/pub/software/scm/git/docs/git-config.html。特别是,您可能有兴趣查看Git 配置示例 https://www.kernel.org/pub/software/scm/git/docs/git-config.html#_example:
# Core variables
[core]
; Don't trust file modes
filemode = false
# Our diff algorithm
[diff]
external = /usr/local/bin/diff-wrapper
renames = true
[branch "devel"]
remote = origin
merge = refs/heads/devel
# Proxy settings
[core]
gitProxy="ssh" for "kernel.org"
gitProxy=default-proxy ; for the rest
[include]
path = /path/to/foo.inc ; include by absolute path
path = foo ; expand "foo" relative to the current file
path = ~/foo ; expand "foo" in your $HOME directory
Edit
解决原贴问的是如何更改user.name and user.email每个存储库 https://stackoverflow.com/questions/18181439/git-different-config-for-different-repository/18181510?noredirect=1#comment26641614_18181510,以下是如何通过命令行执行此操作。切换到每个存储库,然后运行以下命令:
git config user.name "<name>"
git config user.email "<email>"
由于您没有使用--system
or the --global
标志,上述命令将仅适用于您终端工作目录中的任何存储库。