git配置config文件


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

补充:

bc = branch --contains  //git branch --contains <hash> 查看包含hash提交的分支。

 

8. 若变更服务器了,可以使用scp命令来同步git配置(包括私钥) 和其它一些配置

(1) 假设两台机器IP分别为:A.104.238.161.75,B.43.224.34.73,你要从A服务器变更为B服务器,那么需要将A服务器上与git相关的配置文件拷贝到B服务器相同目录下,执行:

scp -r ~/{.ssh,.netrc,.gitconfig} <your job number>@43.224.34.73:<home path>

 

posted on 2019-02-24 21:24  Hello-World3  阅读(2523)  评论(0编辑  收藏  举报

导航