5 ms·
Git and Jujutsu: In Miniature
- wffurr 2y agoThis is all enormously complicated for no reason. If you find the missing tests, just send a PR to add the tests immediately. Why go through all the weirdness of stitching into this development branch? Just add the tests and then rebase your WIP branch on it.
- __float 2y agoThis was just one example, maybe not a perfect one. I found it to be relatable, though. Sometimes the "add the missing tests" step depends on other work on your branch.
- zbentley 2y agoI think the pedantic answer is "if so, your branches/commits are too big." In practice, what you describe is often the case, and having a quick shortcut to do "stick $small_fix in main via a separate branch, but yoink that commit into my branch before that first branch lands on main so I can keep working" would be very useful. Historically, though, I usually addressed this need by copy/pasting the code into separate commits in both branches, and being careful to keep the $small_fix-to-main code and its twin in my larger branch un-drifted and textually discrete to make the eventual merge conflict a rubber-stamp to resolve. Ugly, yes. Maybe I should feel guilty about it, who knows?
- stouset 2y agoThat sounds like a lot of work. And it is a lot of work. Even in the best case. I know it is because I used to do exactly this. But more often than not the small fix ends up getting affected by your changes in the branch and then you're in rebase hell again.
- a10c 2y agoI mean that's the point of the article, no? With Jujutsu it's not at all complicated. Sure, you may not agree with the example (and I would say its a little contrived), but rebasing into history to keep a clean progression of commits in a feature branch that is unreleased is something that many people are keen on. Jujutsu also has a bunch of other really useful features like `jj fix` which can run a code linter over a linear commit history (in parallel) and integrate the changes into the commits that should contain the change. This avoids a litany of 'fix formatting' style commits littered through your history.
- arxanas 2y ago> rebasing into history to keep a clean progression of commits in a feature branch that is unreleased is something that many people are keen on To give some specific examples, "many people" includes popular open-source projects like Linux and Git itself, as well as large tech companies like Google and Meta, which employ "trunk-based development" (see e.g. https://trunkbaseddevelopment.com https://trunkbaseddevelopment.com).
- keybored 2y agoI don’t know what is supposed to be more straightforward about Just Send a PR. This is a short process broken down into every little step. And every step is just within git/jj. Just Send a PR would involve more steps and indirection.
- porridgeraisin 2y agoWhy won't this work to achieve the exact same thing? # on branch `feature` # code code code # whoops! Test missing git add wip/ changes/ && git commit -m lol git checkout develop # write the test git add test/ files/ && git commit -m lol2 # back to WIP branch git checkout feature # open vim and put the lol2 commit in the right place git rebase -i develop ?lol2<cr>dd/3e7<cr>P:wq # undo the original lol commit git reset HEAD~1 You could use git stash instead of making and resetting the `lol` commit but i just prefer to do it this way.
- stouset 2y agoYou can, but this sort of glosses over all the ways this can quickly get confusing. I’ve had this exact scenario happen where develop had multiple commits and the rebase caused a chain of having to resolve rebase conflicts in each commit. Then I fuck up one of those and I have to completely start over. And during this process I’m “stuck” in the rebase state and can’t use regular tools to manage and track my work.
- fragmede 2y agorerere in git config helps, but if jj just does it all more sanely, it's probably worth learning for people who don't yet have the git-fu.
- stouset 2y agoRerere sort of helps, sometimes, but like so many things with git (the stash, wip commits, fixup commits, squash rebasing) it’s yet more hacky fixes over the design being not quite right.
- porridgeraisin 2y agoThe sibling comment mentions rerere. But you can solve this even without that. I assume you mean develop has a few extra commits from remote meaning feature branch diverges a few commits earlier. Let's say the commit where feature branch diverges from has hash `abc`. So what I would do is git checkout abc # write the test, then suppose hash with test files is xyz git checkout feature git rebase --onto xyz abc You will now have test commit as root of feature branch. And now you can move it wherever you want just like in my original answer.
- mitchellh 2y agoWhen people find out I use jj (Jujutsu), I often get asked some version of "how's it better than Git?" And while I can list a number of reasons why I think it's better and you could argue whether or not that reason is contrived or not, I think it's all missing the point. I think it's better -- in the most pessimistic case -- to look at jj as reframing how you think about branches and commits in the same way that learning a type of Lisp reframes your thinking even if you're a full time Python developer and have zero intention of ever using a Lisp. The idea of shuffling commits around without fear, changing your working train of thought mid-branch, etc. is natural... mindless, even. It's one command away and you get so much muscle memory executing that command you just do it automatically. (There's no fear because `jj undo` undoes any operation you did if you regret it. Of course there a ways to undo N operations back and so on too). I use jj full time now, but even when I periodically go back to using git (for older projects I don't have a jj clone out for), it has altered the way I look at my stream of work. I think there's value in that. That's the pessimistic case. The optimistic case is you should be using jj because it's better and there's almost zero downside to doing it (your coworkers don't even need to know). (This blog post was great, I just expect and already see some people focusing on the minutia of how to Git golf your way to achieving the same thing easily when that doesn't invalidate that jj is good, in my opinion).
- steveklabnik 2y agoI didn’t know you were a jj fan! I’ve been a convert for a long time now. I fully agree with what you’ve said here.
- mitchellh 2y agoI am! I think I heard about it through you somehow, actually. And then I kept getting PRs from people I respected with weird branch names and thought "what the hell is going on" and both of these things pushed me to look into it. I switched cold turkey in one afternoon after reading your tutorial in about 30 minutes and never touched Git ever again (except in the very rare cases noted in my previous post). And also... bisect.
- 2y ago
- theamk 2y ago> git really forces me to make a lot of decisions I don’t actually care about. How will I save my WIP while I’m off on this quest? Do I want to juggle stashes and my working tree, or throw commits around? How will I get a commit where I want it? Do I need to come up with a branch name? And how much of all this needs to just sit in my head or pasteboard, lest I forget what I was in the middle of? I am hearing this argument a lot, but I don't really get it. My grocery store forces me to make a lot of decision when it offers me 7 kinds of ketchup and 20+ kinds of cereal, but no one says "I am avoiding large grocery stores because they force me to make too many decisions". If you are feeling adventurous, try something new. If you just want to get some food and go, grab your favorite brands. And yes, a smaller store won't force you to choose, but there is good chance you won't like the food you buy there. (For the problem described, I'd do as following: Save WIP work as temporary commit. No, you don't want to juggle stashes. You can do interactive rebase with "edit" mode and then cherry-pick extra commit - this'll let you make sure test passes after rebase too. Yes, you need to come up with branch name, any will go, like c_s_test. You will need to keep the name of previous branch in your head, but given author uses "develop" it should not be too bad. But this is all my preferences, if someone wants to do something else - more power to them.)
- abhinavk 2y agoA better analogy would be: You have 7 ways to the ketchup section with varying lengths.
- zamalek 2y agoSome will lead you into a universe from which you will never return.
- theamk 2y agoThat can work too... "To get to the ketchup section, I can go via fresh produce row or via bread row or via canned food row... Which path do I pick? Going via produce row is faster but I need to pick up some hot dog buns..." On the other hand IKEA did design their showrooms so there is exactly one recommended way to get to any section. I find this highly annoying, but they keep doing this, so I am guessing some people like it?
- NotACracker 2y agoTo make it overcomplicated for git just to fake a point doesn't do it for me. I am yet to see a real value to use JJ. Those kind of built-up posts I am seeing about JJ on HN tend to push me in the opposite direction. 1) do your test in your current branch, it's related to what you are doing. 2) commit, co master, co -b newtestbranch, PR it, merge in your branch after. You're going to squash rebase at the end anyway...
- roryokane 2y agoI don’t think the article is overcomplicating the Git commands to falsely represent how complicated Git is. I can easily believe that in some contexts, a Git user really would need to do all the steps the author describes. > 1) do your test in your current branch, it's related to what you are doing. The article describes a scenario where you “feel reasonably assured that green CI will mean you’re on the right track, and you’ve been removing parts of the old parser as you introduce the new”. But this one parser feature you discovered was not under test. “The original parser is half-taken to bits,” so perhaps you already deleted the implementation of that feature, not knowing it was depended on. If the implementation were missing, of course you couldn’t test it on your current branch. Okay, let’s say you didn’t delete the implementation yet – but the implementation calls some of the methods you already modified. If you write a test on your current branch, it would only show that your already-modified parser passes the test. You couldn’t be confident that the expectations in the test you wrote actually match the behavior of the old parser. If the old parser acted differently from your tests (even if it was due to a bug), you need to know about that so you can update callers of the old parser to not rely on that behavior any more. To be confident that your new test accurately describes behavior you need to support, you need to run the new test against the “develop” branch. > 2) … You're going to squash rebase at the end anyway... Why would you assume that? Some teams prefer to express changes as a series of independent commits when possible, and they merge PRs while keeping those individual commits. My current team is one example. On such teams, keeping a Git feature branch’s history organized is a real need. If you wonder why a team wouldn’t just squash rebase, I think the goals of keeping commits separate on the main branch are to make debugging tools such as `git log`, `git blame`, and `git bisect` more useful.
- jschrf 2y agoAlways blows my mind how much time we waste talking about Git instead of just using it properly. Cheatsheet: - It's distributed horticulture. Your tools come saran-wrapped to the tree. - Rebase flow. Keep your branches linear. - Merge commits are BS - There is no source control problem that rebase, rebase --onto, reset, and reflog can't fix - Topology is everything. Add this to your aliases: https://stackoverflow.com/questions/1838873/visualizing-branch-topology-in-git/34467298#34467298 https://stackoverflow.com/questions/1838873/visualizing-bran... TL;DR: Keep your branches up to date. Feature flags are a huge red flag. Constant conflicts and the inability to have long lived branches is indicative of poor architecture and project layout. Use "rerere" as a bandaid. Why won't anyone think about the release managers.
- yxhuvud 2y agoThe git example break away from how I use git immediately. I've been burned enough times by stash to not ever use it anymore - just create a new branch immediately.
- sjagoe 2y agoI'd be interested to know how it's burned you. I use stash a lot.
- stouset 2y agoForgetting which branch a set of changes was originally stashed on, having stash conflicts (and forgetting to drop the top of the stash once you've fixed it) are common.
- sjagoe 2y agoI've probably just learned to ignore a lot of that. Stash conflicts are annoying. And I have a long list of stashed changes that I should just purge at this point. All the discussion here has me very interested to look at jj, though. Although most of my git interaction these days is through magit, and changing that will probably be hard.
- deleted 2y ago[deleted]
- deleted 2y ago[deleted]