1.Git有一个工具被称为git config,它允许你获取和设置变量;这些变量可以控制Git的外观和操作的各个方面。这些变量以等级的不同可以被存储在三个不同的位置:
(1) /etc/gitconfig 文件:包含了适用于系统所有用户和所有库的值。如果你传递参数选项’--system’ 给 git config,它将明确的读和写这个文件。
(2) ~/.gitconfig 文件 :具体到你的用户。你可以通过传递--global 选项使Git明确的读或写这个特定的文件。
(3) .git/config位于git目录的config文件,特定指向该单一的库。如果git config 时不加--system 也不加--global选项,那么只作用于当前的git版本库,配置产生的修改都体现在.git/config文件中
三个config文件是逐级覆盖的关系,具体的覆盖非具体的。
2.例子
(1) 用户标识配置
$ git config --global user.name "John Doe" //user.name就是对[user]下的name进行配置
$ git config --global user.email johndoe@example.com
$ cat ~/.gitconfig
[user]
email = johndoe@example.com
name = John Doe
...
这里的修改是针对这个用户的所有git版本库的,若不加--global可以就是只针对某一个具体的版本库起作用,修改体现在.git/config下。
3.更多例子
$ git config --global core.editor emacs 指定你的编辑器
$ git config --global merge.tool vimdiff 指定你的比较工具(Your Diff Tool)
$ git config --list 检查你的设置(Checking Your Settings)
$ git help config 获取帮助(Getting help)
4.分别移除各个等级的一个配置项
git config --unset user.name
git config --unset --global user.name
git config --unset --system user.name
5.移除一组配置项
git config --remove-section color
6. git config get user.name 获取一个属性的值,当然也可以直接cat上面的config文件。
7.我的.gitconfig文件
# cat ~/.gitconfig [user] name = xxx email = xxx@xxx.com [alias] st = status ci = commit [commit] [core] editor = vim [color] ui = auto [push] default = matching [alias] st = status co = checkout ci = commit br = branch lo = log --oneline la = log --author lg = log --graph dc = diff --cached cp = cherry-pick dir = rev-parse --git-dir
8. 使用如下命令,打印更详细信息,可以设置为alias
$ git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ci) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative * 4224e71 - (HEAD -> <branch-name>) <commit-message> (2022-06-01 10:21:04 +0800(注:是提交时间,不是merge时间)) <提交人>
本文参考链接:https://www.cnblogs.com/hellokitty2/p/10428001.html