Once a branch has been merged back in, the merge commit is the marker of its existence. Assuming you don't monkey around too much with your merge commit messages, you could do something like this:
#!/bin/bash
die_with_usage() {
# add a git alias for merged-commits to be able to call it like this
echo "usage: git merged-commits <branch-merged> <branch-merged-into>" 1>&2
exit 1
}
if [ $# -ne 2 ]; then
die_with_usage
fi
# Find the merge commits
merges=($(git log --pretty=%H --grep="Merge branch '$1' into $2"))
if [ ${#merges[@]} -eq 0 ]; then
echo "error: no such merges found!" 1>&2
die_with_usage
fi
for merge in ${merges[@]}; do
# The first parent is the merged-into branch
bar=$merge^1
# The second is the merged branch
foo=$merge^2
# Find the merge base
base=$(git merge-base $bar $foo)
# Show the commits
git log --pretty=%H $base..$foo
done
I figured it'd be helpful to just print the SHA1s and let you go off and do what you like with them afterward, but of course you can fiddle with the output format of that last git log
.
(And I even tested this! Might keep it around; it's a cool little few-liner.)
Another thing you can do (in the future) is adopt a merge commit message along the lines of git.git, which essentially embeds the shortlog of the merged commits in the merged commit message (here's an example). There's a built-in way to do this coming someday (it's been merged to next but not master) but for now you'd have to roll your own, or make a gutsy move and build from next.