How to show the branches which contain the commit in the output of git log -G foo
?
Up to now it looks like this:
commit a24dc0cd5403b697634976f2f7eef4aa7af61b3d
Author: Thomas Guettler <[email protected]>
Date: Mon Aug 8 11:16:30 2022 0200
use timezone, and two tests for one day.
commit 8ffe418ff64b899958cf9da594852a13dc993673
Author: Thomas Guettler <[email protected]>
Date: Mon Aug 8 11:11:29 2022 0200
removed debug code.
I would like it to look like this:
commit a24dc0cd5403b697634976f2f7eef4aa7af61b3d
Author: Thomas Guettler <[email protected]>
Date: Mon Aug 8 11:16:30 2022 0200
Branches: feature-foo
use timezone, and two tests for one day.
commit 8ffe418ff64b899958cf9da594852a13dc993673
Author: Thomas Guettler <[email protected]>
Date: Mon Aug 8 11:11:29 2022 0200
Branches: main feature-foo
removed debug code.
CodePudding user response:
One way to get the branches that contain said commits is to add --simplify-by-decoration
:
# to make sense of how branches relate one to another :
git log --graph --oneline --simplify-by-decoration -G foo
# you can also add '-p' to see the content of selected commits, and you will see that
# the commits are not named individually
# to get just the ref names :
git log --format="%D" --simplify-by-decoration -G foo
The above commands will list any ref (local branches, remote branches, tags, stash
...) that appear in your history.
You can add --decorate-refs=refs/heads
to list only local branches (or --decorate-refs=whatever/suits/your/needs
).
CodePudding user response:
Out of the box, Git cannot embed a shell script in its pretty-format string. Here is a quick & dirty solution. It kind of mimics the format you want, but without colour and without some of the extra information Git might print in certain situations. But I hope it gives you a clue how to continue and refine it.
Preconditions:
- You use a UNIX-like shell, I tried Git Bash on Windows.
- You use GNU sed.
Define this shell function in your profile or directly on the console:
git_log_branches() {
git log --pretty=format:"commit %H%nAuthor: %an