Git 找到所有分支的头提交

Git find the head commit of all branches

是否有可能获得 git 存储库的所有分支以及他们的 head 提交。

如果我有以下存储库:

* b562239 (HEAD -> master) lastCommit
* 3828834 (seccondBranch) seccond Commit 
| * 3f6fdf6 (firstBranch) branchCommit
|/  
* b051ccd init repo

我想要一个这样的列表:

master b562239
seccondBranch 3828834
firstBranch 3f6fdf6

refs 的管道工具是 git for-each-ref

git for-each-ref --format='%(refname:short) %(objectname:short)' refs/heads

获得您想要的确切输出。


同样值得注意的是,git branch -v(或 -vv 甚至更详细)将列出所有分支及其提示指向的提交散列,但以非常冗长的方式,因为它也有关远程分支机构关联/最后提交消息的功能信息。

带有 -v 的分支输出示例:

development    f06f99b5c4 [behind 1] <commit message of commit f06f99b5c4>

-vv 的分支输出示例:

development    f06f99b5c4 [origin/development: behind 1] <commit message of commit f06f99b5c4>