Skip to content

Instantly share code, notes, and snippets.

@Mossop
Created April 25, 2025 08:59
Show Gist options
  • Select an option

  • Save Mossop/60c78aa4d49dcd15da6b5197ce25515e to your computer and use it in GitHub Desktop.

Select an option

Save Mossop/60c78aa4d49dcd15da6b5197ce25515e to your computer and use it in GitHub Desktop.
Rebase children of a bookmark after a git fetch
#! /bin/bash
BOOKMARK="${1:-central}"
OPERATIONS=`jj op log --no-graph --at-op=@ --ignore-working-copy -T 'id ++ ":" ++ description ++ "\n"' | grep -A 1 -m 1 ":fetch from git remote" | sed -e 's/:.*$//g' | xargs echo`
read _ PARENT <<< "$OPERATIONS"
OLD_COMMIT=`jj log --at-op=${PARENT} --ignore-working-copy -r ${BOOKMARK} --no-graph -T 'commit_id'`
NEW_COMMIT=`jj log --at-op=@ --ignore-working-copy -r ${BOOKMARK} --no-graph -T 'commit_id'`
if [ "$OLD_COMMIT" == "$NEW_COMMIT" ]; then
exit
fi
CHANGES=`jj log --ignore-working-copy -r "${OLD_COMMIT}+ & mutable()" --no-graph -T 'change_id'`
if [ -z "$CHANGES" ]; then
exit
fi
jj rebase --skip-emptied -s "all:${OLD_COMMIT}+ & mutable()" -d ${BOOKMARK}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment