Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
executable file 37 lines (29 sloc) 982 Bytes
# 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
git_dir=$(git rev-parse --git-dir)
if [ ! -f "$todo" ]; then
echo "Not in an interactive rebase?" > /dev/stderr
exit 1
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