将下面的内容保存到.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