i'm looking for a list of commits ending with a certain commit id and starting with the commit 10 commits above (newer than) it. Basically i want to find out what happened immediately after a certain commit that might be related to it.
i could do
git log <mycommitid>..HEAD
but that lists thousands of commits, i just want 10
i want to do something like the following, but that's not legal syntax
git log mycommitid^-10..mycommitid
is there a way to do this?
Here's a shell command that will give you what you want:
git log -n 10 "$(git rev-list --reverse <commit id>~.. |head -10 |tail -1)"
The subshell in this case expands to the commit 10 commits in the future from <commit id>
, so it's actually a look backwards starting from that commit. Add the --reverse
argument onto log
to view those commits in reverse order, oldest to newest.
Unfortunately, in Git's syntax for specifying commit ranges there is no operator for going forward in history. You only have ~
and ^
which refer to parent or ancestor commits. It's going to have to be a subshell or nothing.
Here's an alternate command that will give the diff as well as the commit log.
git show $(git rev-list --reverse <commit id>~.. |head -10)
(The reason I had to use |head
here is because git rev-list --reverse -n 10 <commit range>
gives the 10 latest commits in the range, meaning it applies the limiter BEFORE the reversal, which is likely a bug.)