Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 38 lines (29 sloc) 982 Bytes
#!/bin/bash
#
# While in an interactive git-rebase, this allows to go back to a previous commit,
# like if you were doing a rebase inside a rebase.
#
# Under the hood what it actually does is to reset to the commit passed as argument,
# and prepend the range <commit>..HEAD to the git-rebase's todo file
#
set -ex
if [ $# -lt 1 ]; then
echo "missing commit to rebase onto" > /dev/stderr
exit 1
fi
commit=$1
git_dir=$(git rev-parse --git-dir)
todo="$git_dir/rebase-merge/git-rebase-todo"
if [ ! -f "$todo" ]; then
echo "Not in an interactive rebase?" > /dev/stderr
exit 1
fi
new_todo=$(mktemp --tmpdir git-recursive-rebase.XXXXXXXXXX)
git log --reverse $commit..HEAD --format="pick %H %s" > "$new_todo"
# insert a break so we are back to the previously stopped place
echo "x echo \"recursive-rebase previously stopped here\"" >> "$new_todo"
echo "break" >> "$new_todo"
cat "$todo" >> "$new_todo"
# replace todo
mv "$new_todo" "$todo"
git reset --hard $commit
You can’t perform that action at this time.