2.6 KiB
2.6 KiB
Rebase Current Changeset
You are tasked with rebasing the current changeset onto the primary branch.
Process:
-
Determine the primary branch:
- Run
jj log -r 'bookmarks()' --no-graphto list all bookmarks - Check if
mainormasterexists in the bookmark list - If
mainexists, use it as the primary branch - If
maindoesn't exist butmasterdoes, usemasteras the primary branch - If neither exists, ask the user: "What is the name of your primary branch?"
- Wait for the user's response before proceeding
- Run
-
Pull latest changes:
- Run
jj git fetchto fetch the latest changes from the remote - This ensures we're rebasing onto the latest version of the primary branch
- Run
-
Identify the changeset to rebase:
- Run
jj log -r 'mine() & ::@'to see the current changeset and its ancestors - The current changeset is marked with
@in the log - Identify the changeset ID of the current working copy (the one with
@)
- Run
-
Rebase the changeset:
- Run
jj rebase -s <changeset-id> -d <primary-branch> - Where
<changeset-id>is the ID of the current working copy - Where
<primary-branch>is the primary branch determined in step 1 - This rebases the current changeset and all its descendants onto the primary branch
- Run
-
Show the result:
- Run
jj logto display the updated commit tree - Confirm to the user that the rebase was successful
- Run
Important:
- DO NOT rebase changesets that are part of bookmarks you plan to delete
- Only rebase the current changeset chain, not other branches
- If there are conflicts during rebase, report them to the user and stop
- Use
jj git fetchinstead ofjj git pullto avoid automatic merging
Jujutsu-specific notes:
jj rebase -s <source> -d <destination>rebases the source changeset and all its descendants- The
-sflag specifies the source changeset to rebase - The
-dflag specifies the destination to rebase onto - Jujutsu handles rebasing automatically, updating the working copy
- Use changeset IDs or revision expressions (like
@for current working copy)
Error handling:
- If
jj git fetchfails, report the error and stop - If the primary branch doesn't exist locally, report this and ask the user to verify
- If rebase fails due to conflicts, report the conflicts and provide guidance
- If the user is not on a changeset that can be rebased, explain why
Remember:
- Rebasing updates the working copy to be based on the latest primary branch
- This is useful before creating pull requests or pushing changes
- The user trusts your judgment to identify the correct changeset to rebase