我想打印git日志,以便使用它所在的分支打印每个提交。
我尝试使用各种版本的git log,但没有一个使用EVERY提交打印分支名称。
git log --author=user --all --decorate --oneline
git log --pretty='%Cblue%h%C(cyan)%d%Cred %cn %Cgreen %ar %Creset %s'
git log --pretty=format':%h [%an] %s%d' --graph --date=short --all --date-order
git log --pretty=format':%h [%an] %s%d\' --graph --date=short --all --date-order
git log --pretty=format':\"%h [%an] %s%d\' --graph --date=short --all --date-order
git log --pretty=format:\"%h [%an] %s%d\" --graph --date=short --all --date-order
git log --pretty=format:\"%h %ad [%an] %s%d\" --graph --date=short --all --date-order
我知道git中的分支只是提交的指针,特定的提交可能属于多个分支。
答案 0 :(得分:3)
Git没有内置任何内容来执行此操作。
一个非常缓慢但简单的方法是使用git rev-list
来获取git log
将显示的相同提交ID,然后运行git log --no-walk --pretty=tformat:'...'
(tformat添加换行符,您可以包含一个明确的每个此类ID的格式,包括从git branch --contains
获得的分支名称:
for sha1 in $(git rev-list --all --date-order); do
# season below to taste, this is very primitive
contains=$(echo $(git branch --all --contains $sha1 | sed 's/^..//'))
git log --pretty=tformat:"%h [%an] %s ($contains)" --no-walk $sha1
done
您可能想要更聪明和/或更快的内容,但编写代码更难。
(请注意,使用--all
可获得远程分支,如果remotes/origin/HEAD
是间接分支,则remotes/origin/HEAD -> origin/master
会在$contains
处获得{{1}}。)