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

一. 配置文件的存储位置

Git相关的配置文件有三个

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

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

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

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


二. 一些有用的配置项

1. 设置别名

[alias] 为git命令配置别名

例:

[plain]  view plain  copy
  1. [alias]  
  2.     st = status  
  3.     ci = commit  
  4.     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
  1. [color]  
  2.     ui = true  

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

对比一下,无此配置时

加入配置后



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

[plain]  view plain  copy
  1. [core]  
  2.     filemode = false  

4.使用vimdiff呈现Git diff差异

[plain]  view plain  copy
  1. [diff]  
  2.     tool = vimdiff  
  3. [difftool]  
  4.     prompt = false  
  5. [alias]  
  6.     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
  1. git config core.filemode true   
执行后会在配置文件中添加 
[plain]  view plain  copy
  1. [core]  
  2.     filemode = true  

3.删除配置项

git config [–local|–global|–system] –unset section.key

猜你喜欢

转载自blog.csdn.net/yuxin6866/article/details/74835735