zoukankan      html  css  js  c++  java
  • git常用配置

    git常用配置

     
    配置SSH主机明白
    在.ssh目录创建config文件
    内容格式为
    host 主机命名
        user  连接服务器的用户名
        hostname 服务器ip地址或机器名
        identityFile 密匙文件的具体路径
     
    例如:    
    us@scm_fan:~$ cat .ssh/config
    host gitSZ
        user git
        hostname 192.168.10.204
        identityFile ~/.ssh/id_rsa.pub
     
    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"
    diff颜色配置  color.diff true
    设置别名 alias.co checkout
    git config --global alias.co checkout 
     
    查看配置信息
    git config --list
     
    直接查阅某个环境变量的设定
    git config user.name

    忽略修改权限的文件
    git config core.filemode false
     
    也可以通过编辑$GIT_DIR/info/exclude 文件将你需要忽略的文件写入其中与.gitignore文件的区别,就是这个你只能自己用不能通过提交.gitignore文件给整个项目组用。
    通过git config --global core.excludesfile ~/.gitignore  对本机上的所有仓库进行忽略文件配置
     

    忽略文件中的空格修改
    git config --global apply.whitespace nowarn

    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 的时候如果有多个文件,将会逐个显示,关闭掉当前文件窗口就会显示下一个文件。
     
     上面多个文件比较时是足够显示的,下面设置类似于文件夹的比较
          可以将 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等等。
  • 相关阅读:
    剑指Offer-30.连续子数组的最大和(C++/Java)
    剑指Offer-29.最小的K个数(C++/Java)
    UVA 1616 Caravan Robbers 商队抢劫者(二分)
    UVA 10570 Meeting with Aliens 外星人聚会
    UVA 11093 Just Finish it up 环形跑道 (贪心)
    UVA 12673 Erratic Expansion 奇怪的气球膨胀 (递推)
    UVA 10954 Add All 全部相加 (Huffman编码)
    UVA 714 Copying Books 抄书 (二分)
    UVALive 3523 Knights of the Round Table 圆桌骑士 (无向图点双连通分量)
    codeforecs Gym 100286B Blind Walk
  • 原文地址:https://www.cnblogs.com/Ph-one/p/5702756.html
Copyright © 2011-2022 走看看