Вопрос

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.

Другие советы

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top