常用命令
统计今天写了多少代码
git log --since=midnight --author="$(git config user.name)" --pretty=tformat: --numstat | awk '{add += $1; del += $2; loc += $1 - $2} END {print "新增:", add, "删除:", del, "净增:", loc}'git log --since="1 week ago" --author="$(git config user.name)" --pretty=format:"%ad" --date=short --numstat | awk '
/^[0-9]{4}-[0-9]{2}-[0-9]{2}/ {
date = $0; next
}
NF == 3 {
add[date] += $1
del[date] += $2
loc[date] += $1 - $2
}
END {
for (d in add)
print d, "新增:", add[d], "删除:", del[d], "净增:", loc[d]
}' | sortclone 特定分支
git clone -b v5.12 git@gitee.com:xxx/xxx.git直接创建并跟踪远程分支
git ck -b feature-tszz_iter1.0 origin/feature-tszz_iter1.0日志查看
git log --graph --pretty=oneline --abbrev-commit添加远程库
git remote add origin git@github.com:michaelliao/learngit.git第一次推送
git push -u origin master比较差异
git diff readme.txt配置别名
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
git config --global alias.lg "log --graph --pretty=oneline --abbrev-commit"
git config --global alias.st "status"
git config --global alias.ck "checkout"
git config --global alias.br "branch"标签
- 命令
git tag <tagname>用于新建一个标签,默认为HEAD,也可以指定一个commit id; - 命令
git tag -a <tagname> -m "blablabla..."可以指定标签信息; - 命令
git tag可以查看所有标签。 - 命令
git push origin <tagname>可以推送一个本地标签; - 命令
git push origin --tags可以推送全部未推送过的本地标签; - 命令
git tag -d <tagname>可以删除一个本地标签; - 命令
git push origin :refs/tags/<tagname>可以删除一个远程标签。
获取今天的日志
git log --since="6am"暂存
# 暂存包含新增的文件(即未跟踪)并注释 msg
git stash save -u "msg"
# 应用指定暂存
git stash apply stash@{1}错误记录
pull 或 merge 时错误
fatal: refusing to merge unrelated histories