git配置文件

一. 配置文件的存储位置

git相关的配置文件有三个

1. /etc/gitconfig:包括了适用于系统全部用户和全部项目的值。

2.~/.gitconfig:仅仅适用于当前登录用户的配置。

3. 位于git项目文件夹中的.git/config:适用于特定git项目的配置。

对于同一配置项,三个配置文件的优先级是1<2<3


二. 一些实用的配置项

1.[alias] 为git命令配置别名

例:

[alias]
    st = status
    ci = commit
    br = branch 

当你有了上述配置后。使用git st等同于使用git stauts


2. [color] 设置git输出着色

例:

[color]
    ui = true

设置color.ui为true来打开全部的默认终端着色。

对照一下,无此配置时

增加配置后



3. core.filemode 让git忽略对文件权限的改动

[core]
    filemode = false

4.使用vimdiff呈现Git diff差异

[diff]
    tool = vimdiff
[difftool]
    prompt = false
[alias]
    d = difftool
使用时仅仅需将用到git diff的地方换为git d就能够了。


三. 用git config操作配置文件

1. 列出当前配置项

git config [–system|–global|–local] -l
使用system, golbal, local时。分别列出相应一部分中的1,2。3三个文件之中的一个的配置项。
假设不加上述三个选项,则会按一部分中所说的优先级合并全部配置项并输出。

2.加入配置项 
git config [–local|–global|–system]  section.key value
例:
git config core.filemode true 
运行后会在配置文件里加入 
[core]
    filemode = true

3.删除配置项
git config [–local|–global|–system] –unset section.key

原文地址:https://www.cnblogs.com/brucemengbm/p/6912095.html