So I've been hovering around jj for a while, trying to understand how it works, without suceeding in having a good mental model around it.
I looked at this megamerge workflow and it's the first one that "clicked" for me (even though I'm not sure I understand the magic behind jj absorb, but I'll look into it).
One thing though is that I don't quite understand how it would work in the context of a real git repo. Let's say I work on two branches, main and feature1, I'd create a [merge] commit that is has the two bookmarks as parents. But if after a fetch main has new changes, do I need to discard the current [merge] and recreate it again ? I can't find a way to just say "Update the parents so they track these bookmarks".
I just tried it on a real repo, working on a change in a branch, then on a change on another branch, then adding a third branch I needed to work on that was not a parent yet, but this seems like a lot of boilerplate to always recreate my megamerge setup so I think I'm missing something
> One thing though is that I don't quite understand how it would work in the context of a real git repo.
Just to be clear, `jj` stores all of its stuff in a real git repo. I know you probably meant "using git instead of jj" but I wanted to point that out because it means that you can just go look at what it does. I will say that sometimes that can be confusing, and I'd be very careful running git commands that modify history inside that directory.
Let's say that we pull down our remote, and main has changed, as you've said. There is a new commit on top of it.
We can simulate this in jj. (q is valid because we have so few changes there's no others that start with q yet)
jj new v --no-edit -m "changes from upstream"
Created new commit trzwxsrr c8318f5f (empty) changes from upstream
jj bookmark create -r t main@origin
Created 1 bookmarks pointing to trzwxsrr c8318f5f main@origin | (empty) changes from upstream
So now we get to the issue: git would want us to rebase every one of these branches individually. When we rebase A (19d713aab65d0e572994634b2487ce7637d6752a) on top of main@origin (c8318f5fd641a9b271b67e90e7ca1c465b1a92da), well: (don't do this in a real repo, since this is an example I'm okay with trashing things, I even made a copy of the repo before doing this)
git checkout 19d713aab65d0e572994634b2487ce7637d6752a
Previous HEAD position was d29e741
HEAD is now at 19d713a A
git rebase main@origin
git log --all --graph
* commit f397936ac0d4510682e68ab470eb81863a5c2a73 (HEAD)
| Author: Steve Klabnik <steve@steveklabnik.com>
| Date: Wed Feb 12 13:25:29 2025 -0600
|
| A
|
* commit c8318f5fd641a9b271b67e90e7ca1c465b1a92da (refs/jj/keep/c8318f5fd641a9b271b67e90e7ca1c465b1a92da, main@origin)
| Author: Steve Klabnik <steve@steveklabnik.com>
| Date: Wed Feb 12 13:27:16 2025 -0600
|
| changes from upstream
|
| *-. commit 79d7cf16869f0f293b18ff4fa339d2d053b537c0 (refs/jj/keep/79d7cf16869f0f293b18ff4fa339d2d053b537c0)
|/|\ \ Merge: d29e741 19d713a 2df38e4 9403fc7
| | | | Author: Steve Klabnik <steve@steveklabnik.com>
| | | | Date: Wed Feb 12 13:25:41 2025 -0600
| | | |
| | | * commit 9403fc75d2ec85491d990c7322b0f5f8f500fa78 (refs/jj/keep/9403fc75d2ec85491d990c7322b0f5f8f500fa78)
| | |/ Author: Steve Klabnik <steve@steveklabnik.com>
| | | Date: Wed Feb 12 13:25:34 2025 -0600
| | |
| | | C
| | |
| | * commit 2df38e4eccbd31ef70a810dd86c637cc2110912c (refs/jj/keep/2df38e4eccbd31ef70a810dd86c637cc2110912c)
| |/ Author: Steve Klabnik <steve@steveklabnik.com>
| | Date: Wed Feb 12 13:25:32 2025 -0600
| |
| | B
| |
| * commit 19d713aab65d0e572994634b2487ce7637d6752a (refs/jj/keep/19d713aab65d0e572994634b2487ce7637d6752a)
|/ Author: Steve Klabnik <steve@steveklabnik.com>
| Date: Wed Feb 12 13:25:29 2025 -0600
|
| A
|
* commit d29e7411f098bba0120cfd5b819b732dabcb6f73 (refs/jj/keep/d29e7411f098bba0120cfd5b819b732dabcb6f73, main)
Author: Steve Klabnik <steve@steveklabnik.com>
Date: Wed Feb 12 13:25:25 2025 -0600
We only get one branch. So what we'd have to do is go back and fix up every single branch here, including our merge. And so yeah, you can do it, but it's a giant pain in the butt. And for the children, you really need --onto, so you'd end up doing something like
$ git checkout 2df38e4eccbd31ef70a810dd86c637cc2110912c
$ git rebase HEAD --onto f397936ac
$ git checkout 9403fc75d2ec85491d990c7322b0f5f8f500fa78
$ git rebase HEAD --onto <new head of branch the first rebase committed>
for every branch. HOWEVER, git has introduced --update-refs, which can automate this. But it's from 2022, and my Ubuntu is a bit old, and so I cannot actually try it out.
That allll being said, I also don't know how well --update-refs does with the mega merge commit itself.
> this seems like a lot of boilerplate to always recreate my megamerge setup so I think I'm missing something
I mean, the entire thesis here is that stuff is easier in jj than it is in git: it doesn't mean you're missing something it means that git can be a bit clunky sometimes.