logoalt Hacker News

IshKebab • today at 10:19 AM • 3 replies • view on HN

Here's my current workflow:

1. I write some code.

2. I realise it makes sense to commit as two commits.

3. I stage changes for the first commit & commit it.

4. I stage the remaining changes and commit those.

How would that work in JJ? I guess you do things in a different order somehow?


Replies

dieortin • today at 10:24 AM

You would just use jj split to break the working commit into two, choosing which parts to put in which commit

nchmy • today at 10:44 AM

Someone already said this, but you just use jj split. Either split the whole file or use interactive mode to split the exact lines. You could also use squash if you want to move it to an existing revision/commit.

Jj makes it vastly more efficient and ergonomic to perform surgery across commits - no staging area to think about, remember, stumble over, etc. Conflicts don't stop the world.

It's all dead simple if you use jjui - don't even need to learn any jj syntax

ssivark • today at 10:38 AM

The stuff you wrote is always captured in a commit and never in some weird lingering (uncommitted) state.

Treat the HEAD commit like your staging area. Split it as you will, pick stuff you like, remove stuff you don't want and push it to a different commit, etc. Feel free to rewrite history as you will (that you haven't exposed publicly, for others to depend on).