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

骑猪看日落 2022-06-13 13:52 567阅读 0赞

一. 配置文件的存储位置

Git相关的配置文件有三个

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

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

  1. 位于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 这种快捷方式:

  1. 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 ,实际执行的是“

  1. 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来打开所有的默认终端着色。

对比一下,无此配置时

20150605174459537

加入配置后

20150605174529333

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

发表评论

表情:
评论列表 (有 0 条评论,567人围观)

还没有评论,来说两句吧...

相关阅读

    相关 git忽略文件配置

    有三种方法可以实现忽略Git中不想提交的文件 1. 在Git项目中定义 .gitignore 文件 这种方式通过在项目的某个文件夹下定义 .gitignor