Reputation: 607
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.
Upvotes: 6
Views: 4936
Reputation: 1
This is what worked for me best to find all parents of a commit: I looked for all parents of Merge3. So I did
git log HEAD^
which gave me the first parent Merge2. Then I did
git log HEAD^2
which gave me the second parent C4. Then I did:
git log HEAD^3
which gave me an error. So I knew I have found all parents. I moved to C4 with
git checkout C4
and so on.
Upvotes: 0
Reputation: 60275
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.
Upvotes: 2
Reputation: 607
A possible solution is using --graph
then some sed and grep magic.
This kinda works but it's hacky, was hoping that git-log
would be able to do this for me!
I think it needs additional options to show the proper order and not, say, by commit date.
git log --oneline --graph \
| sed -e 's|[^a-z0-9]*||1' \
| egrep -v '^[a-z0-9]+ Merge' \
| egrep -v "^$"
The first sed
removes the branches "ascii art" that --graph
mode outputs.
The first grep
removes all merge commits.
The second grep
removes empty lines.
Upvotes: 1