Created
January 18, 2017 09:23
-
-
Save smola/d53d4ad23c3363576fba9492b60bce15 to your computer and use it in GitHub Desktop.
Find all initial commits and the commits where they were merged
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# git-find-roots finds every commit with no parent (initial commits) | |
# and the commit where they were merged. | |
# | |
# Usage: | |
# git-find-roots [commit-ish] | |
# | |
# Example: | |
# git-find-roots master | |
# | |
BRANCH=${1:-master} | |
find_roots() { | |
branch=$1 | |
git rev-list --max-parents=0 $branch | |
} | |
find_merge() { | |
commit=$1 | |
branch=$2 | |
perl -ne 'print if ($seen{$_} .= @ARGV) =~ /10$/' <(git rev-list --ancestry-path $commit..$branch) <(git rev-list --first-parent $commit..$branch) | tail -n 1 | |
} | |
for root in $(find_roots $BRANCH) ; do | |
merge=$(find_merge $root $BRANCH) | |
echo "root $root was merged in $merge" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To clarify, it finds all root commits of the specified branch, which is not necessarily ALL root commits in the repository.