jj
jj copied to clipboard
FR: Split based on remote tip to prevent force-pushing branches in review
Hi all, I'm loving to work with jj, my team less so because now lots of PRs are rebased and github doesn't play nicely with that (you can't easily review the diff between your last review and current state, ie incremental reviews and branch changes).
One of the problems I face is accidentally editing the revision at the tip of a branch in review, so what I'd like to have is a way of splitting changes in that revision (even better is the entire branch) into a new revision such that when I jj git push the branch moves forward only.
In the image above we can see that pl has changes the remote doesn't. What I'd want is to move all extra changes to nx (or a new revision, it doesn't matter) and restore pl to what the remote has.
In this case I ended up rebasing pl into the remote tip jj rebase -s pl -d 949d996b, squashing the local pl into nx (jj squash --from 0ddfd3ba --into nx) and fixing all the conflicts, which was easy because there were only a few changes, but that's not always the case.
Aside, I'd also love if there was a way to always ask for confirmation before moving a branch sideways when pushing as a safety check.
Thanks! Awesome work btw!
I'm not sure if you're already aware of this or if it would be helpful, but if you want to prevent accidentally rewriting commits in a bookmark, you could add the bookmark to immutable_heads() to make the commits immutable. If you want to rewrite the commits sometimes though, this may not be ideal.
Perhaps, this is basically the same feature request as https://github.com/jj-vcs/jj/issues/5818?
In the meantime I believe you can (following the steps here) do the following to split a commit according to what's in a remote:
jj new -A mybranch -m 'new changes' # You have already done this step in the screenshot
jj restore --from mybranch@origin --into mybranch --restore-descendants
The --restore-descendants flag means that only the state of that commit is modified, while the descendants will still have the same code as it had before the command.