git show last few commits leading back to a merge-base

379 views Asked by At

Two branches diverged a long time ago (e.g. devel and master). I'd like to show the history either side of that divergence point, e.g. +/-10 commits. (This is to decide how to recapture the old branches give a change in naming convention)

It is easy to locate the merge-base (git merge-base devel master), and to show the 10 commits before that (e.g. git log --oneline -10 $(git merge-base devel master)).

But I'm not sure how to locate the points 10 commits before (more recent than) the merge-base to limit the commit range displayed (e.g. with show-branch).

Is there a way to the n'th more recent commit along a given line of development?

1

There are 1 answers

4
jthill On BEST ANSWER

For this you just want grep's context option.

git log devel master --no-abbrev-commit --oneline --date-order \
| grep -10 $(git merge-base devel master)

If you want the graph structure drawn for those, git log has to print some lines without commits to keep everything connected properly and that will mess with your counts. So get the raw commit ids first and then tell log to graph them all explicitly:

git rev-list --date-order devel master \
| grep -10 $(git merge-base devel master) \
| xargs git log -21 --graph --decorate --oneline