11 comments

  • chriswarbo1 hour ago
    Magit allows selective staging&#x2F;unstaging, either of hunks, or by selecting lines (AKA Emacs&#x27;s &quot;region&quot;). I avoid staging from the git commandline, unless I&#x27;m just doing whole files.<p>PS: Majutsu provides this too (a magit-like tool for jj)
    • PaulDavisThe1st9 minutes ago
      The per-line staging in magit is a frequent tool I use. I can be in the middle of bunch of other changes, change 1 line for a different reason that would otherwise be &quot;mid-hunk&quot;, and the stage &amp; commit it with its own explanation.<p>It releases me from having to have the &quot;discipline&quot; to stay 100% focused on the broader task at hand and say &quot;hmm, I should fix that while I&#x27;m here&quot;, without co-mingling purposefully different commits.<p>Truly fantastic. Absurdly, I have no idea how to do this on the command line, though presumably it is possible from there too (just a lot, lot less convenient).
    • paustint25 minutes ago
      VSCode also allows staging&#x2F;unstaging specific hunks by hovering over the hunk near the left&#x2F;right separator in diff view - super handy when I need it!
    • rbjorklin54 minutes ago
      Neogit, Magit inspired, does the same for Neovim. Would recommend!
      • skydhash46 minutes ago
        I think you can do the same with tig and lazyvim. Sometimes you just need interactivity.
  • BeetleB1 hour ago
    &gt; If you’re not already using git add -p to stage your commits then you’re missing out.<p>After switching to jujutsu, I assure you I don&#x27;t miss this feature.<p>jj takes the opposite approach. It keeps staging things, and you use <i>split</i> whenever you want to separate things out.<p>(And yes, it stores the staged changes as revisions, so you can always back out to a previous staged state).
    • hamdingers28 minutes ago
      &gt; jj takes the opposite approach. It keeps staging things, and you use split whenever you want to separate things out.<p>You can use `git reset -p` to selectively unstage hunks the same way if you wanted to.
    • pmarreck1 hour ago
      I&#x27;ve sadly had to back out of using jj after leaning into LLM coding assistance, as, even with an extremely well-written jj guide in its context (and literally <i>blocking the use of git</i>), it never failed to screw things up more than if I was just using git (I call this an &quot;LLMpedance mismatch&quot; problem)<p>If LLM coding assistance continues to increase, it&#x27;s going to be a rather large speed bump to cross<p>One of the biggest problems is actually unsolvable if you want to keep colocated Git and git tooling around, because it has to do with how jj fundamentally works: detached HEADs, detached HEADs everywhere<p>You yourself may not use AI, this is for those who do and are interested in switching to jj
      • BeetleB1 hour ago
        I don&#x27;t let LLMs make commits for me - git or jj.<p>OK, OK - I lie. For personal projects I do - some handle jj decently well. But at work I don&#x27;t let it make any commits ... and it never tries to.<p>What tools are you using that won&#x27;t work with detached heads?
  • natbennett1 hour ago
    In the case of a newly committed file you can add just the file with<p>git add . -N<p>And then review the text itself as part of the git add -p workflow
  • ninkendo1 hour ago
    My biggest problem with `add -p` is correcting any patches I added or rejected by accident. Often times I skip through dozens of things I don’t want to add, then realized that last hunk was something I <i>did</i> need. But I can’t re-visit it, I have to start over and try extra hard to not skip past it again.<p>I wish the j and k shortcuts could revisit hunks I’ve already added&#x2F;rejected, not just ones I haven’t reviewed yet. On a large set of unstaged changes that you mostly don’t want, it really sucks to “lose your place” in the list of hunks.
    • topsecret38 minutes ago
      From the article, try J and K instead of j and k; that moves to next&#x2F;previous hunk, not next&#x2F;previous unreviewed hunk.
    • ghrl49 minutes ago
      From skimming through the article, isn&#x27;t that what the uppercase variants do?
  • goosejuice1 hour ago
    I always use git add -i which is just one level up. The tui is pretty intuitive for day to day tasks, including staging partial chunks or lines of code.
  • wren699142 minutes ago
    The worst part of this workflow is when you accidentally run `git commit -am` at the end and destroy all of your careful staging.
  • zikohh2 hours ago
    I find splitting hunks a pain. I wish I could just split by line, would be a great feature.
    • PaulDavisThe1st7 minutes ago
      to make the list closer to complete, magit in emacs allows this (Ctrl-space on the line, done).
    • elevation1 hour ago
      &gt; splitting hunks a pain<p>Sublime Merge for the win; a fantastic visual interface with context and reversible inputs. Don&#x27;t leave home without it!
    • LVB1 hour ago
      Use &#x27;e&#x27; in -p mode and you can edit the hunks as you wish, choose lines, etc.
      • embedding-shape1 hour ago
        The whole &quot;Stage this hunk [y,n,q,a,d,k,K,j,J,g,&#x2F;,e,p,P,?]?&quot; line is pretty intimidating, but I urge anyone who still wants to understand git and be able to (themselves) use it effectively, to do &quot;?&quot; when you see it, read through what each action does and forcefully try them out to see what they do, in some low stakes project. Ends up being a super quick way of staging a whole bunch of work and avoiding staging other, but it&#x27;s pretty weird at first glance.
      • feelamee1 hour ago
        it&#x27;s not as easy as you said. it can be tricky and complicated to use edit mode. I usually use it, but still often don&#x27;t understand - will this edit succeed or why it is failed.
    • KwanEsq1 hour ago
      Mercurial&#x27;s `hg commit -i` with the curses interface is so much better for this it&#x27;s not even funny. Fortunately I&#x27;d assume Jujutsu&#x27;s UX is similar, based on arccy&#x27;s comment.
    • petepete1 hour ago
      I&#x27;ve used tig for longer than I can remember for my selective staging needs.
    • arccy1 hour ago
      use jj, the default is to select by line
  • prideout1 hour ago
    Super useful, and easy to do in the VS Code merge pane.
  • Topgamer74 days ago
    I find grepdiff and this function are pretty useful if you want to pull certain hunks out of a large change set:<p><pre><code> #!&#x2F;bin&#x2F;bash # Put this into your .bashrc, or whatever. function git-add-regex { git diff -U0 | grepdiff -E &quot;$1&quot; --output-matching=hunk | git apply --cached --unidiff-zero } </code></pre> <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;smuuf&#x2F;76bde33d65b3dbbc2411e8519f3e6c18" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;smuuf&#x2F;76bde33d65b3dbbc2411e8519f3e6c...</a>
  • deepsun2 hours ago
    IntelliJ has that since 2018, with visual change-by-change checkboxes that should go into each commit, very handy.
  • cerved1 hour ago
    Vin fugitives difftool is even better<p>Also, you can use -p for stash push
    • feelamee1 hour ago
      and also for git restore
      • juliend251 minutes ago
        and also for `git reset`, when you added one thing by mistake.