git常用配置

来源:互联网 发布:淘宝如何延迟确认收货 编辑:程序博客网 时间:2024/05/22 04:38
个人使用:vim ~/.vimconfig

1. git config --system  /etc/gitconfig文件: 系统中对所有用户都普遍使用的配置
2. git config --global   ~/.gitconfig文件: 用户目录下的配置文件只适用于该用户
3. 当前项目的git目录中的配置文件(工作区中的.git/config文件): 只针对当前项目有效。每个一个级别的配置都会覆盖上层的相同配置,所以.git/config的配置会覆盖/etc/gitconfig中的配置
[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. user.name  //用户信息的配置  
  2. user.email  
  3. core.editor  //文本编辑器  
  4. merge.tool  //差异分析工具  
  5. core.paper "less -N"  //配置显示方式  
  6. color.diff true  //diff颜色配置  
  7. alias.co checkout  //设置别名  
  8. git config --global alias.co checkout   
  9. git config --list  //查看配置信息 !  
  10. git config user.name  //直接查阅某个环境变量的设定  
  11. git config core.filemode false  //忽略修改权限的文件  
[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. <span style="color: rgb(73, 73, 73); font-size: 14px; line-height: 22.399999618530273px;">git config --global apply.whitespace nowarn  //<span style="color: rgb(73, 73, 73); font-size: 14px; line-height: 22.399999618530273px;">忽略文件中的空格修改</span></span>  
也可以通过编辑$GIT_DIR/info/exclude 文件将你需要忽略的文件写入其中与.gitignore文件的区别,就是这个你只能自己用不能通过提交.gitignore文件给整个项目组用。
通过git config --global core.excludesfile ~/.gitignore  对本机上的所有仓库进行忽略文件配置
 
7. 颜色配置
[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. color.branch auto  
  2. color.diff auto  
  3. color.interactive auto  
  4. color.status auto  
  5. color.ui true  //将颜色全部打开  
  6. [color]  
  7. branch = auto  
  8. diff = auto  
  9. status = auto  
  10. [color "branch"]  
  11. current = yellow reverse  
  12. local = yellow   
  13. remote = green  
  14. [color "diff"]  
  15. meta = yellow bold  
  16. frag = magenta bold  
  17. old = red bold  
  18. new = green bold  
  19. [color "status"]  
  20. added = yellow  
  21. changed = green  
  22. untracked = cyan  

8. 将默认的.git目录改为.test
修改shell 参赛 GIT_DIR=> export GIT_DIR=.test
 
忽略某些文件
通过创建名为.gitignore的文件,列出要忽略的文件模式,例如:
[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. $cat .gitignore  
  2. *.[oa]    #忽略所有以.o或.a结尾的文件  
  3. *~    #忽略所有以波浪符(~)结尾的文件  
  4. !lib.a #lib.a 除外  
  5. /TODO #仅仅忽略项目根目录下的TODO文件,不包括subdir/TODO  
  6. build/    #忽略build/目录下的所有文件  
  7. doc/*.txt #会忽略doc/note.txt 但不包括doc/server/arch.txt  
git命令bieming
[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. git config --global alias.co checkout  
commit.template 提交说明模板
[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. git config --global  commit.template  $HOME/.gitmessage.txt  
core.pager 分页器,可以设置成more或者less(默认),甚至为空
[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. git config  --global  core.pager ''     不管命令的输出量多少,都会在一页显示所有内容  
user.signingkey 将GPG签署密匙设为配置项
设置密匙ID   git   config   --global  user.signingkey  <gpg-key-id>
这样就不必每次运行git  tag 命令时定义密匙
[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. git   tag  -s   <tag-name>  
core.excludesfile定义无需纳入GIt管理的文件
创建一个内容和.gitignore类似的文件
[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. git  config  --global core.excludesfile   path-filename  
help.autocorrect
该配置项在1.6及以上版本有效
命令补全和提示
color.ui  Git会按照你需要自动为大部分的输出加上颜色
[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. git  config  --global  color.ui  true  
其他参数还有false和always      false意味着不为输出着色,而always则表明在任何情况下都要着色
[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. color.*  设置具体的命令  
  2. color.branch  
  3. color.diff  
  4. color.interactive  
  5. color.status  
每个选项都有子选项,可以被用来覆盖其父设置。
core.autocrlf  处理行结束符
[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. true  在提交时将CRLF转换为LF  当签出代码时,LF会被转换成CRLF  
  2. input 在提交是将CRLF转换为LF ,签出时不转换  
  3. 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忽略这种情况
[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. git config core.filemode false  这条命令只能git库中执行  
 
4. 配置优先级
[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. git config -e  信息写在版本库中.git/config文件 针对单个版本库的配置信息  
  2. git config -e --global  信息写在用户主目录下的.gitconfig  针对当前用户的配置信息  
  3. git config -e --system 信息写在/etc/gitconfig   针对整个操作  
 
优先级别依次降低
git配置文件使用的是INI文件格式。
[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. git config命令可以读取和更改INI配置文件的内容。  
  2. git config <section>.<key>  
  3. git config <section>.<key> <value>  
删除配置内容
[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. $git config --unset --global user.name  
  2. $git config --unset --global user.email  

5. remote 远程库信息配置
[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. 添加远程库 git remote add  远程库名称  地址  
  2. 删除远程库 git remote rm 远程库名称  
  3. 设置远程地址 git remote set-url  远程库名称 地址  
  4. git config --get  remote.origin.url  获取远程库路径  
 
通过git clone --bare 命令克隆的裸库是没有远程库的,需要手动添加,在添加了远程库之后git config --list 会多出如下两项
[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. remote.origin.url=gitSZ:mt6573/platform/build.git  
  2. remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*  
  3. 可以手动编译git config  remote.origin.fetch=+refs/*:refs/*  来匹配所有改动  
  4. remote.origin.mirror=true 作用不明?  
6. 配置第三方图形化比较工具meld
[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. A. 在/usr/local/bin 目录下创建extDiff 文件  
  2.      cd /usr/local/bin  
  3.      sudo gedit /usr/local/bin  
  4.       内容为:  
  5.       #!/bin/bash  
  6.       /usr/bin/meld "$2" "$5"  
  7.      这里的/usr/bin/meld可以替换成其他的工具  
  8.      保存退出  
  9.  B. 添加执行权限  
  10.       sudo +x extDiff  
  11.  C.  配置git  
  12.       git config --global diff.external extDiff  
  13.       配置完成  
   在执行git diff 的时候如果有多个文件,将会逐个显示,关闭掉当前文件窗口就会显示下一个文件。

 上面多个文件比较时是足够显示的,下面设置类似于文件夹的比较
[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. A. 从https://github.com/thenigan/git-diffall 下载脚本  
  2.      可以将 git-diffall 放置在任意目录,添加可执行权限,我放在 /usr/local/bin  
  3.     chmod o+x git-diffall    
  4. B. git config --global alias.diffall  /usr/local/bin/git-diffall  
  5. C . git diffall  tag1   tag2  
 配置完成
 

配置比较工具:
安装bcompare
下载.tar.gz 解压后执行install.sh 在[usr]输入/opt 按提示设置环境变量(64位ubuntu10.10测试成功,相同的方法12.04测试失败)
配置git
[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. difftool  
  2. git config --global diff.tool bc3  
  3. git config --global difftool.bc3 trustExitCode  
  4.    
  5. mergetool  
  6. git config --global merge.tool bc3  
  7. 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
0 0
原创粉丝点击