您的位置:首页 > 其它

git常用配置

2014-04-21 13:25 357 查看
个人使用:vim ~/.vimconfig

1. git config --system  /etc/gitconfig文件: 系统中对所有用户都普遍使用的配置

2. git config --global   ~/.gitconfig文件: 用户目录下的配置文件只适用于该用户

3. 当前项目的git目录中的配置文件(工作区中的.git/config文件): 只针对当前项目有效。每个一个级别的配置都会覆盖上层的相同配置,所以.git/config的配置会覆盖/etc/gitconfig中的配置

user.name  //用户信息的配置
user.email
core.editor  //文本编辑器
merge.tool  //差异分析工具
core.paper "less -N"  //配置显示方式
color.diff true  //diff颜色配置
alias.co checkout  //设置别名
git config --global alias.co checkout
git config --list  //查看配置信息 !
git config user.name  //直接查阅某个环境变量的设定
git config core.filemode false  //忽略修改权限的文件
git config --global apply.whitespace nowarn  //忽略文件中的空格修改


也可以通过编辑$GIT_DIR/info/exclude 文件将你需要忽略的文件写入其中与.gitignore文件的区别,就是这个你只能自己用不能通过提交.gitignore文件给整个项目组用。

通过git config --global core.excludesfile ~/.gitignore  对本机上的所有仓库进行忽略文件配置

 

7. 颜色配置
color.branch auto
color.diff auto
color.interactive auto
color.status auto
color.ui true  //将颜色全部打开
[color]
branch = auto
diff = auto
status = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow bold
frag = magenta bold
old = red bold
new = green bold
[color "status"]
added = yellow
changed = green
untracked = cyan


8. 将默认的.git目录改为.test

修改shell 参赛 GIT_DIR=> export GIT_DIR=.test

 

忽略某些文件

通过创建名为.gitignore的文件,列出要忽略的文件模式,例如:

$cat .gitignore
*.[oa]    #忽略所有以.o或.a结尾的文件
*~    #忽略所有以波浪符(~)结尾的文件
!lib.a #lib.a 除外
/TODO #仅仅忽略项目根目录下的TODO文件,不包括subdir/TODO
build/    #忽略build/目录下的所有文件
doc/*.txt #会忽略doc/note.txt 但不包括doc/server/arch.txt


git命令bieming

git config --global alias.co checkout


commit.template 提交说明模板

git config --global  commit.template  $HOME/.gitmessage.txt


core.pager 分页器,可以设置成more或者less(默认),甚至为空

git config  --global  core.pager ''     不管命令的输出量多少,都会在一页显示所有内容


user.signingkey 将GPG签署密匙设为配置项

设置密匙ID   git   config   --global  user.signingkey  <gpg-key-id>

这样就不必每次运行git  tag 命令时定义密匙

git   tag  -s   <tag-name>


core.excludesfile定义无需纳入GIt管理的文件

创建一个内容和.gitignore类似的文件

git  config  --global core.excludesfile   path-filename


help.autocorrect

该配置项在1.6及以上版本有效

命令补全和提示

color.ui  Git会按照你需要自动为大部分的输出加上颜色

git  config  --global  color.ui  true


其他参数还有false和always      false意味着不为输出着色,而always则表明在任何情况下都要着色

color.*  设置具体的命令
color.branch
color.diff
color.interactive
color.status


每个选项都有子选项,可以被用来覆盖其父设置。

core.autocrlf  处理行结束符

true  在提交时将CRLF转换为LF  当签出代码时,LF会被转换成CRLF
input 在提交是将CRLF转换为LF ,签出时不转换
false  取消此功能


core.whitespace 探测和修改空白问题,其4种抓选项中的2个默认被打开,另2个被关闭

默认被打开的2个选项是trailing-space和space-before-tab    trailinig-space会查找每行结尾的空格,  space-before-tab 会查找每行开头的制表符前的空格

默认被关闭的2个选项是indent-with-non-tab和cr-at-eol    indent-with-non-tab会查找8个以上空格(非制表符)开头的行, cr-at-eol 让Git指定行尾回车符是合法的

 

git config branch.autosetupmerge true

自动从远程分支合并提交到本地分支,如果不做此设置你需要手动add track远程分支或手动merge  默认就是true

git config branch.autosetuprebase always   设置在pull是做rebase还是merge 可选的值有never 不自动rebase,local跟踪本地分支的分支进行rebase,remote 跟踪远程分支的进行rebase , always所有的跟踪分支都自动进行rebase

3.有时候git clone下来后,文件的权限不对,需要chmod -R 777 .

但是这样git会发现很多的改变,事实上是不需要提交的。通过下面的配置可以让git忽略这种情况

git config core.filemode false  这条命令只能git库中执行


 

4. 配置优先级

git config -e  信息写在版本库中.git/config文件 针对单个版本库的配置信息
git config -e --global  信息写在用户主目录下的.gitconfig  针对当前用户的配置信息
git config -e --system 信息写在/etc/gitconfig   针对整个操作


 

优先级别依次降低

git配置文件使用的是INI文件格式。
git config命令可以读取和更改INI配置文件的内容。
git config <section>.<key>
git config <section>.<key> <value>

删除配置内容
$git config --unset --global user.name
$git config --unset --global user.email


5. remote 远程库信息配置
添加远程库 git remote add  远程库名称  地址
删除远程库 git remote rm 远程库名称
设置远程地址 git remote set-url  远程库名称 地址
git config --get  remote.origin.url  获取远程库路径

 
通过git clone --bare 命令克隆的裸库是没有远程库的,需要手动添加,在添加了远程库之后git config --list 会多出如下两项
remote.origin.url=gitSZ:mt6573/platform/build.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
可以手动编译git config  remote.origin.fetch=+refs/*:refs/*  来匹配所有改动
remote.origin.mirror=true 作用不明?


6. 配置第三方图形化比较工具meld

A. 在/usr/local/bin 目录下创建extDiff 文件
cd /usr/local/bin
sudo gedit /usr/local/bin
内容为:
#!/bin/bash
/usr/bin/meld "$2" "$5"
这里的/usr/bin/meld可以替换成其他的工具
保存退出
B. 添加执行权限
sudo +x extDiff
C.  配置git
git config --global diff.external extDiff
配置完成


   在执行git diff 的时候如果有多个文件,将会逐个显示,关闭掉当前文件窗口就会显示下一个文件。

 上面多个文件比较时是足够显示的,下面设置类似于文件夹的比较

A. 从https://github.com/thenigan/git-diffall 下载脚本
可以将 git-diffall 放置在任意目录,添加可执行权限,我放在 /usr/local/bin
chmod o+x git-diffall
B. git config --global alias.diffall  /usr/local/bin/git-diffall
C . git diffall  tag1   tag2


 配置完成

 

配置比较工具:

安装bcompare

下载.tar.gz 解压后执行install.sh 在[usr]输入/opt 按提示设置环境变量(64位ubuntu10.10测试成功,相同的方法12.04测试失败)

配置git

difftool
git config --global diff.tool bc3
git config --global difftool.bc3 trustExitCode

mergetool
git config --global merge.tool bc3
git config --global mergetool.diffmerge.cmd "cmld = bc3 --merge --result=$MERGED $LOCAL $BASE $REMOTE"


bcompare可以换成其他git支持的工具如果meld、kdiff3等等。

 

文章转自:http://www.cnblogs.com/AKMFAN/articles/3438161.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  git gitconfig 配置