-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-splay
More file actions
executable file
·42 lines (34 loc) · 916 Bytes
/
git-splay
File metadata and controls
executable file
·42 lines (34 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
set -e
USAGE="git splay BASE PREFIX {CMD}
For each commit in BASE..HEAD, create a new branch PREFIX/N which is that commit, rebased onto BASE.
If PREFIX is '-', prompts for each name.
If CMD is given, runs that CMD for each branch thus created.
Example: Create branches and push them:
git splay master changes git push
"
if [ "$#" -lt 2 ]; then
echo "$USAGE" >&2
exit 1
fi
BASE="$1"
PREFIX="$2"
shift 2
COMMITS=($(git log --format=%H "$BASE..")) # split on whitespace and make array
n=0
for commit in "${COMMITS[@]}"; do
if [ "$PREFIX" == "-" ]; then
git --no-pager show --quiet "$commit"
echo
read -p "Branch name? " branch
else
branch="$PREFIX/$((n++))"
fi
git branch "$branch" "$BASE"
git checkout "$branch"
git cherry-pick "$commit"
[ "$#" -gt 0 ] && "$@"
done
# This seems as sane a choice as any to leave the state in
echo "Done. Returning to $BASE"
git checkout "$BASE"