Git 常用命令总结

将下面的内容保存到.gitconfig文件,放到当前用户的home目录下,使用git工具更便捷。

[alias]
    st = status
    br = branch
    ci = commit
    co = checkout
    mr = merge
    st = status
    ci = commit
    cia = commit --amend
    che = cherry-pick
    di = diff
    fe = fetch --all
    lg = log -p
    lga = log -p --all
    lol =  log --graph --decorate --pretty=oneline --abbrev-commit
    lola = log --graph --decorate --pretty=oneline --abbrev-commit --all
    lgg =  log --graph --decorate --pretty=format:'%C(yellow)%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --all
    loa = log --graph --decorate --abbrev-commit --all
    lll = log --pretty=format:\"%H %an, %ar : %s\"
    ls = ls-files
    rh = reset --hard
    l1h = log -1 HEAD
    l1p = log -1 -p
    lns = log --name-staus
    lno = log --name-only
    lst = log --stat
    lwc = whatchanged
    lwcs = whatchanged --stat

查看git config的信息:

git config --local -l 查看仓库配置【必须要进入到具体的目录下,比如要查看TestGit仓库的配置信息】

git config --global -l 查看用户配置

git config --system -l 查看系统配置

git config -l 查看所有的配置信息,依次是系统级别、用户级别、仓库级别

clone repo

git clone -b [branch] [URL] [Dir]

查看代码提交记录:

git annotate -L <start>,<end> file

git blame file -L <start>,<end>

拉起指定commit 到当前分支

git cherry-pick [commit1..commit2]

删除远端分支:

[Wed May 15 16:12 admin@:~/product-nas]$ git br -r -d origin/zm-dev

Deleted remote-tracking branch origin/zm-dev (was eab9faa).

git push origin --delete  [extremenas]

设置bash命令行的分支信息

function git-branch-name {
  git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3
}
function git-branch-prompt {
  local branch=`git-branch-name`
  if [ $branch ]; then printf " (%s) " $branch; fi
}

export PS1="\[\e[37;0m\][\d \A \[\e[33;1m\]\u\[\e[33;1m\]:\[\e[36;1m\]\w\[\e[37;0m\]\$(git-branch-prompt)]\$ " 

 

查看分支的创建信息

git reflog show --date=iso  feature-encrypt

Checkout指定commit的文件

git checkout -- <commitid> <file>

批量Checkout分支:

#!/bin/bash

branch=$1
basedir=$(cd `dirname $0`;pwd)
service=$2
isCreate="no"
echo "Current Dir: $basedir"

if [ x"$branch" = x ]; then
    echo ""
    echo "Error! You must specify checkout branch!"
    echo "$0 [branch]"
    echo "Example:"
    echo "      $0 master"
    echo ""
    exit
fi

if [ x"$service" == x"" ]; then
    service=$(ls -d pattern*)
fi
for path in ${service[@]}
do
    cur="$basedir/$path"
    echo "[DIR] : $cur"
    cd $cur
    git reset --hard HEAD  # Avoid to conflict with local modified files
    isExisted=$(git br -a | grep "origin/$branch\$")
    if [ x"$isExisted" == x"" ]; then
        echo "[$branch] doesn't existed"
        read -p "Do you want to create it, if yes, will clone based on live? [yes/no]: " choice
        if [ x"$choice" == x"yes" -o x"$choice" == x"y" ]; then
            git co -b $branch -t origin/live
            git push -f origin $branch
            git br --set-upstream-to origin/$branch
        else
            exit
        fi
    fi
    isExistedLocal=$(git br | grep "$branch\$")
    if [ x"$isExistedLocal" == x"  $branch" -o x"$isExistedLocal" == x"* $branch" ]; then
        git co $branch
        git pull
    else
        git checkout -b $branch -t origin/$branch
        git pull
    fi
    echo ""
done

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值