Friday, June 21, 2013

Git config

This post is from here.


git的全局配置,存储于$HOME/.gitconfig里,这里的配置影响当前用户的所有git repo

命令行里,通过git config--global参数开启全局配置
$: git config --global user.name yyfrankyy
$: git config --global user.email yyfrankyy@gmail.com

默认编辑器

$: git config --global core.editor vim

默认merge/diff 工具

注意设置后需要通过difftoolmergetool来启动
$: git config --global diff.tool vimdiff
$: git config --global difftool.prompt false
$: git difftool file.js

通过Alias 设置别名

一些常用的命令,可以通过设置别名来减少输入
分支切换是比较频繁的操作
$: git config --global alias.br branch
$: git br
* master
  prepub
日志也是经常需要看的
$: git config --global alias.last log --pretty=oneline -1 HEAD
$: git last
eba0f64370036ca57aa50b9938a3e70755f74aaa 我只是提交一下看看log..
以及上面提到的difftool
$: git config --global alias.df difftool

repo 级别的配置

repo级别的配置,存储在仓库目录的.git/config文件中这里的所有配置项跟全局一致,可以覆盖全局信息
比如公司项目,指定花名和公司邮箱:
$: git config user.name wenhe
$: git config user.email wenhe@taobao.com
git本身也会用于存储该库的远程仓库,分支列表等信息
$: cat .git/config
[core]
 repositoryformatversion = 0
 filemode = true
 bare = false
 logallrefupdates = true
[remote "s"]
 url = git@search.ued.taobao.net:projects/search.git
 fetch = +refs/heads/*:refs/remotes/s/*
[branch "master"]
 remote = s
 merge = refs/heads/master
[branch "prepub"]
 remote = s
 merge = refs/heads/prepub
[branch "product"]
 remote = s
 merge = refs/heads/product

我的全局配置[2010-10-22 ]

$: cat ~/.gitconfig
[user]
 name = yyfrankyy
 email = yyfrankyy@gmail.com
[core]
 excludesfile = /home/wenhe/.gitignore
 quotepath = false
 editor = vim
[alias]
 co = checkout
 ci = commit
 br = branch
 st = status
 unstage = reset HEAD --
 last = log -1 HEAD
 mg = merge
 glog = log --pretty=oneline --graph
 df = difftool
[color]
 ui = true
[format]
 pretty = oneline
[diff]
 tool = gvimdiff
[difftool]
 prompt = false
[merge]
 tool = gvimdiff
最新的gitconfig文件,可以到 这里 查看

References 

No comments:

Post a Comment