In a shared GitHub repository, I would like to use git log
to show a list of recent commits.
The current history is similar to the following:
(master)
B------Merge1--Merge2--Merge3
/ / /
- -C1 / /
- - -C2 /
- - -C3----------C4
Where the Merge
commits are result of a merged pull request, and the C
commits are coming from forks of this repository.
git log
shows something like this:
git log --oneline master
Merge3
Merge2
Merge1
B
But what I'm really interested in are the C
commits.
git log --graph
is the only possible way I found to show C1, C2 and C3.
Is there any other option (not involving --graph
) that would show C1, C2, and C3?
I would like to be able to do something like this
git log --oneline --no-merges <...insert magic here...> master
C4
C3
C2
C1
B
The only sensible thing I found in the man page is --first-parent
, but i found no way to disable or invert it.
If you're not doing your merges and pulls with --no-ff
having actual merge commits at a branch tip is going to be an unreliable indicator, so if you just don't want to see the merge commits,
git log --no-merges --oneline -n 10 # or --since, or something, might do
If you want to decide how far back to list based on commit attributes rev-list doesn't have as a built-in cutoff criterion it's just a matter of filtering on those attributes in the output of rev-list
or more generally some log --pretty=format:
selection, here's one that lists only the tips from merged branches leading to the selected branch, getting C1-C2-C4 -- since I can't figure out how you decided to bypass C4 ...
#!/bin/sh
git rev-list --parents "${@-HEAD}" \
| sed -n '/^[^ ]* [^ ]* /!q;s///;s/[^ ]*/&^!/gp' \
| xargs git log --oneline
The sed:
/^[^ ]* [^ ]* /!q # quit at first rev with less than two parents
s/// # strip rev and its first parent
s/[^ ]*/&^!/gp # append ^! to all other (merged) revs
and the ^!
suffix tells log
to not automatically include parents.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With