您的位置:首页 > 其它

git 配置文件位置;git配置文件设置

2017-07-08 15:46 232 查看

一. 配置文件的存储位置

Git相关的配置文件有三个

1. /etc/gitconfig:包含了适用于系统所有用户和所有项目的值。

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

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

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


二. 一些有用的配置项

1. 设置别名

[alias] 为git命令配置别名

例:

[plain] view
plain copy

[alias]

st = status

ci = commit

br = branch

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

甚至有人丧心病狂的 设置 git lg 这种快捷方式:

git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
这样 git lg ,实际执行的是“
git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
”,效果还是不错的。


2. 输出颜色

[color] 设置git输出着色

例:

[plain] view
plain copy

[color]

ui = true

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

对比一下,无此配置时



加入配置后




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

[plain] view
plain copy

[core]

filemode = false


4.使用vimdiff呈现Git diff差异

[plain] view
plain copy

[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
例:

[plain] view
plain copy

git config core.filemode true

执行后会在配置文件中添加

[plain] view
plain copy

[core]

filemode = true

3.删除配置项

git config [–local|–global|–system] –unset section.key
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息