如果我的本地人正在跟踪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)
是否可以针对任意分支而不是我正在跟踪的远程分支获取相同的信息?
答案 0 :(得分:1)
以下内容将向您展示[other branch]
而非您自己的提交。
git log HEAD..[other branch]
将其与其他一些开关/ CLI工具相结合,您可以获得类似的信息,例如:
git log HEAD..origin/whatever --oneline | wc -l
...将显示origin/whatever
上您的分支上不存在的提交数量。如果您要交换HEAD
和origin/whatever
,您可以查看您的分支机构中存在多少次提交,而不是另一次提交
答案 1 :(得分:1)
当然,只需创建一个高级别名:
$ 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.