git查看两个任意分支之间的提交计数差异

git查看两个任意分支之间的提交计数差异,git,Git,如果我的本地用户正在跟踪origin/master并运行git status,我会收到一条非常有用的消息,告诉我: Your branch and 'origin/master' have diverged, and have 7 and 11 different commits each, respectively. (use "git pull" to merge the remote branch into yours) 是否可以针对任意分支而不是我正在跟踪的远程分支获取相同

如果我的本地用户正在跟踪origin/master并运行git status,我会收到一条非常有用的消息,告诉我:

Your branch and 'origin/master' have diverged,
   and have 7 and 11 different commits each, respectively.
   (use "git pull" to merge the remote branch into yours)

是否可以针对任意分支而不是我正在跟踪的远程分支获取相同的信息?

以下内容将向您显示存在于[其他分支]而不是您自己的分支上的提交

git日志头..[其他分支]

将其与其他一些Switch/CLI工具结合使用,您可以获得类似的信息,例如:

git log HEAD..origin/whatever-oneline | wc-l


…将显示源/分支上不存在的任何内容上存在多少提交。如果您要交换HEAD和origin/which,您将看到有多少提交存在于您的分支上,而不是其他分支上

当然,只需创建一个小小的高级别名:

$ git config alias.branch-diff '!branch_diff() { [ $# -ne 2 ] && echo '\''error: branch-diff needs exactly two arguments'\'' >&2 && exit 1; echo -e "'\''$1'\'' and '\''$2'\'' have diverged,\n   and have $(git log --oneline $2..$1 | wc -l) and $(git log --oneline $1..$2 | wc -l) different commits each, respectively."; }; branch_diff'
$ git branch-diff 8.1.0
error: branch-diff needs exactly two arguments
$ git branch-diff 8.1.0 8.1.1
'8.1.0' and '8.1.1' have diverged,
   and have 800 and 4122 different commits each, respectively.