Skip to content

Instantly share code, notes, and snippets.

@carstene1ns
Last active October 4, 2020 11:56
Show Gist options
  • Save carstene1ns/ab5fa1b9f5d19fa1deae3f8c630141e7 to your computer and use it in GitHub Desktop.
Save carstene1ns/ab5fa1b9f5d19fa1deae3f8c630141e7 to your computer and use it in GitHub Desktop.
Get all commits of the current branch since creation from another branch

Usage

Show all commits the current feature branch has:

$ git show -s $(./git-branch-commits.sh)

Cherry-Pick all commits the specific pull request (checked out as branch) has:

$ git cherry-pick $(./git-branch-commits.sh pr/2215)
#!/bin/bash
branch=$1
base=${2:-master}
if [ -z "$branch" ]; then
branch=$(git branch --show-current)
if [ -z "$branch" ]; then
echo "Provide a branch!"
exit 1
fi
fi
git rev-list --reverse $branch --not $(git rev-list $base ^$branch --merges | tail -1)^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment