- 查看分支最后提交的人, sort命令见最后, -k5n -k2M -k3n -k4n就是按时间排序
git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' | sort -k5n -k2M -k3n -k4n
或者
git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' --sort=committerdate
- 批量删除远程feature和hotfix分支,按日期排序前10个
git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' --sort=committerdate | grep jiangjunshen | grep remotes | grep -E "feature|hotfix" | awk -F' ' 'NR<10 {print $NF}' | sed 's/refs\/remotes\/origin\///g' | xargs -I {} git push origin :{}
- 批量删除远程feature和hotfix分支,名称中含有特定字符串
git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' --sort=committerdate | grep remotes | grep -E "feature|hotfix" | awk -F' ' ' {print $NF}' | grep jjs | sed 's/refs\/remotes\/origin\///g' | xargs -I {} git push origin :{}
- git log设置别名
git config --global alias.lm "log --no-merges --color --date=format:'%Y-%m-%d %H:%M:%S' --author='你的名字!自己修改!' --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Cblue %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit"
git config --global alias.lms "log --no-merges --color --stat --date=format:'%Y-%m-%d %H:%M:%S' --author='你的名字!自己修改!' --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Cblue %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit"
git config --global alias.ls "log --no-merges --color --graph --date=format:'%Y-%m-%d %H:%M:%S' --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Cblue %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit"
git config --global alias.lss "log --no-merges --color --stat --graph --date=format:'%Y-%m-%d %H:%M:%S' --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Cblue %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit"
- 本地分支以及远程分支重命名
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
- 查看远程分支信息以及修剪远程分支
git remote show origin
git remote prune origin
- 给分支打tag以及推送到远端
git tag {tagName}
git push origin {tagName}
git push [origin] --tags
- 清除未追踪的文件和文件夹
git clean -fd
git clean -xfd(无视.gitignore)
git clean -nfd(预览会被清除的文件)
- 扫描 Log 单独统计每个人的增删行数加强版
git log --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --author="$name" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -; done
- 查看A分支上有而B分支上没有的commit
git log B..A
git log B..A --author={name}
sort [OPTION]... [FILE]...
选项说明:
-c:检测给定的文件是否已经排序。如未排序,则会输出诊断信息,提示从哪一行开始乱序。
-C:类似于"-c",只不过不输出任何诊断信息。可以通过退出状态码1判断出文件未排序。
-m:对给定的多个已排序文件进行合并。在合并过程中不做任何排序动作。
-b:忽略字段的前导空白字符。空格数量不固定时,该选项几乎是必须要使用的。"-n"选项隐含该选项。
-d:按照字典顺序排序,只支持字母、数值、空白。除了特殊字符,一般情况下基本等同于默认排序规则。
--debug:将显示排序的过程以及每次排序所使用的字段、字符。同时还会在最前几行显示额外的信息。
-f:将所有小写字母当成大写字母。例如,"b"和"B"是相同的。
:在和"-u"选项一起使用时,如果排序字段的比较结果相等,则丢弃小写字母行。
-k:指定要排序的key,key由字段组成。key格式为"POS1[,POS2]",POS1为key起始位置,POS2为key结束位置。
-n:按数值排序。空字符串""或"\0"被当作空。该选项除了能识别负号"-",其他所有非数字字符都不识别。
:当按数值排序时,遇到不识别的字符时将立即结束该key的排序。
-M:按字符串格式的月份排序。会自动转换成大写,并取缩写值。规则:unknown<JAN<FEB<...<NOV<DEC。
-o:将结果输出到指定文件中。
-r:默认是升序排序,使用该选项将得到降序排序的结果。
:注意:"-r"不参与排序动作,只是操作排序完成后的结果。
-s:禁止sort做"最后的排序"。
-t:指定字段分隔符。
:对于特殊符号(如制表符),可使用类似于-t$'\t'或-t'ctrl+v,tab'(先按ctrl+v,然后按tab键)的方法实现。
-u:只输出重复行的第一行。结合"-f"使用时,重复的小写行被丢弃。