我在.gitconfig
中使用此别名列出两个REF之间缺少的修订:
[alias]
missing = "!f() { test $# -gt 1 && { first=$1; second=$2; } || { first=HEAD; second=$1; }; git rev-list $first..$second --oneline | sed -e 1i'\\ ' -e '1iOnly in '$second: -e 's/^/ /'; git rev-list $second..$first --oneline | sed -e 1i'\\ ' -e '1iOnly in '$first: -e 's/^/ /'; }; f"
为了便于阅读,表达式扩展为多行:
test $# -gt 1 && { first=$1; second=$2; } || { first=HEAD; second=$1; }
git rev-list $first..$second --oneline | sed -e 1i'\\ ' -e '1iOnly in '$second: -e 's/^/ /'
git rev-list $second..$first --oneline | sed -e 1i'\\ ' -e '1iOnly in '$first: -e 's/^/ /'
示例用法和输出:
$ git missing master feature123
Only in feature123:
4e34a98 added example for not enough tests
f3031cb improved some good examples
Only in master:
9a7c6dc added short example
有更好的方法吗? (例如,git
命令已经足够接近。)
有没有更好的方法来编写别名?填充在一行上的长链命令很难读懂。