jj icon indicating copy to clipboard operation
jj copied to clipboard

FR: Split based on remote tip to prevent force-pushing branches in review

Open felipemoran opened this issue 8 months ago • 3 comments
trafficstars

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.

Image

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!

felipemoran avatar Mar 05 '25 12:03 felipemoran

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.

scott2000 avatar Mar 05 '25 13:03 scott2000

Perhaps, this is basically the same feature request as https://github.com/jj-vcs/jj/issues/5818?

yuja avatar Mar 05 '25 14:03 yuja

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.

anka-213 avatar May 27 '25 19:05 anka-213