News for hackers. Stuff that matters.
Re:The Timeless 9 Golden Rules of Debugging by jerf on Monday January 13, 2025 @09:22AM (#42683673)
"git bisect" is why I maintain the discipline that all commits to the "real" branch, however you define that term, should all individually build and pass all (known-at-the-time) tests and generally be deployable in the sense that they would "work" to the best of your knowledge, even if you do not actually want to deploy that literal release. I use this as my #1 principle, above "I should be able to see every keystroke ever written" or "I want every last 'Fixes.' commit" that is sometimes advocated for here, because those principles make bisect useless.

The thing is, I don't even bisect that often... the discipline necessary to maintain that in your source code heavily overlaps with the disciplines to prevent code regression and bugs in the first place, but when I do finally use it, it can pay for itself in literally one shot once a year, because we get bisect out for the biggest, most mysterious bugs, the ones that I know from experience can involve devs staring at code for potentially weeks, and while I'm yet to have a bisect that points at a one-line commit, I've definitely had it hand us multiple-day's-worth of clue in one shot.

If I was maintaining that discipline just for bisect we might quibble with the cost/benefits, but since there's a lot of other reasons to maintain that discipline anyhow, it's a big win for those sorts of disciplines.

Re:The Timeless 9 Golden Rules of Debugging by SoftTalker on Monday January 13, 2025 @12:14PM (#42685801)
I do bisecting almost as a last resort. I've used it when all else fails only a few times. Especially as I've never worked on code where it was very easy to just build and deploy a working debug system from a random past commit.
Re:The Timeless 9 Golden Rules of Debugging by skydhash on Monday January 13, 2025 @10:10AM (#42684220)
Same. Every branch apart from the “real” one and release snapshots is transient and WIP. They don’t get merged back unless tests pass.
Re:The Timeless 9 Golden Rules of Debugging by forrestthewoods on Monday January 13, 2025 @11:37AM (#42685317)
> why I maintain the discipline that all commits to the "real" branch, however you define that term, should all individually build and pass all (known-at-the-time) tests and generally be deployable in the sense that they would "work" to the best of your knowledge, even if you do not actually want to deploy that literal release

You’re spot on.

However it’s clearly a missing feature that Git/Mercurial can’t tag diffs as “passes” or “bisectsble”.

This is especially annoying when you want to merge a stack of commits and the top passes all tests but the middle does not. It’s a monumental and valueless waste of time to fix the middle of the stack. But it’s required if you want to maintain bisectability.

It’s very annoying and wasteful. :(

Re:The Timeless 9 Golden Rules of Debugging by Izkata on Monday January 13, 2025 @12:25PM (#42685947)
If there's a way to identify those incomplete commits, git bisect does support "skip" - a commit that's neither good nor bad, just ignored.
Re:The Timeless 9 Golden Rules of Debugging by JetSetIlly on Tuesday January 14, 2025 @02:31AM (#42694711)
Can we use git trailers for this? Something like "commit: incomplete" in the commit message.
Re:The Timeless 9 Golden Rules of Debugging by michalsustr on Monday January 13, 2025 @12:28PM (#42685976)
Re:The Timeless 9 Golden Rules of Debugging by snowfarthing on Monday January 13, 2025 @01:54PM (#42687104)
As someone who doesn't like to see history lost via "rebase" and "squashing" branches, I have had to think through some of these things, since my personal preferences are often trampled on by company policy.

I have only been in one place where "rebase" is used regularly, and now that I'm a little more familiar with it, I don't mind using it to bring in changes from a parent branch into a working branch, if the working branch hasn't been pushed to origin. It still weirds me out somewhat, and I don't see why a simple merge can't just be the preferred way.-

I have, however, seen "squashing" regularly (and my current position uses it as well as rebasing) -- and I don't particularly like it, because sometimes I put in notes and trials that get "lost" as the task progresses, but nonetheless might be helpful for future work. While it's often standard to delete "squashed" branches, I cannot help but think that, for history-minded folks like me, a good compromise would be to "squash and keep" -- so that the individual commits don't pollute the parent branch, while the details are kept around for anyone needing to review them.

Having said that, I've never been in a position where I felt like I need to "forcibly" push for my preferences. I just figure I might as well just "go with the flow", even if a tiny bit of me dies every time I squash or rebase something, or delete a branch upon merging!

Re:The Timeless 9 Golden Rules of Debugging by rlkf on Monday January 13, 2025 @05:23PM (#42690282)
I use git-format-patch to create a list of diffs for the individual commits before the branch gets squashed, and tuck them away in a private directory. Several times have I gone back to peek at those lists to understand my own thoughts later.
Re:The Timeless 9 Golden Rules of Debugging by Izkata on Monday January 13, 2025 @06:04PM (#42690751)
> I cannot help but think that, for history-minded folks like me, a good compromise would be to "squash and keep" -- so that the individual commits don't pollute the parent branch, while the details are kept around for anyone needing to review them.

But not linked together and those "closed" branches are mixed in with the current ones.

Instead, try out "git merge --no-ff" to merge back into master (forcing a merge commit to exist even if a fast-forward was possible) and "git log --first-parent" to only look at those merge commits. Kinda squash-like, but with all the commits still there.

Re:The Timeless 9 Golden Rules of Debugging by r-bryan on Monday January 13, 2025 @10:40PM (#42693314)
Well dang, we are not restricted to git as the only place we can put historical metadata. You know, discursive comments, for starters?
Re:The Timeless 9 Golden Rules of Debugging by plagiarist on Thursday January 23, 2025 @08:13PM (#42809645)
I think if you find the notes and trials as helpful for reasoning, likely other people might enjoy them as documentation in the final version?
Re:The Timeless 9 Golden Rules of Debugging by forrestthewoods on Monday January 13, 2025 @01:20PM (#42686620)
I explicitly don’t want squash. The commits are still worth keeping separate. There’s lots of distinct pieces of work. But sometimes you break something and fix it later. Or you add something new but support different environments/platforms later.
Re:The Timeless 9 Golden Rules of Debugging by gregthelaw on Monday January 13, 2025 @03:59PM (#42689210)
But if you don't squash, doesn't this render git bisect almost useless?

I think every commit that gets merged to main should be an atomic believed-to-work thing. Not only does this make bisect way more effective, but it's a much better narrative for others to read. You should write code to be as readable by others as possible, and your git history likewise.

Re:The Timeless 9 Golden Rules of Debugging by Izkata on Monday January 13, 2025 @06:08PM (#42690799)
Individual atomic working commits don't necessarily make a full feature. Most of the time I build features up in stages and each commit works on its own, even without completing the feature in question.
Re:The Timeless 9 Golden Rules of Debugging by forrestthewoods on Monday January 13, 2025 @06:14PM (#42690870)
You should read my original comment.

git bisect should operate on bisectable commits. Which may not be all commits. Git is missing information. This is, imho, a flaw in Git.

Re:The Timeless 9 Golden Rules of Debugging by badmintonbaseba on Tuesday January 14, 2025 @09:37AM (#42697693)
git bisect --first-parent
Re:The Timeless 9 Golden Rules of Debugging by badmintonbaseba on Tuesday January 14, 2025 @09:36AM (#42697681)
git bisect supports --first-parent, no need to squash if you just merge.
Re:The Timeless 9 Golden Rules of Debugging by rlkf on Monday January 13, 2025 @05:27PM (#42690340)
Could you not use --first-parent option to test only at the merge-points?
Re:The Timeless 9 Golden Rules of Debugging by aag on Monday January 13, 2025 @01:29PM (#42686767)
Sometimes you'll find a repo where that isn't true. Fortunately, git bisect has a way to deal with failed builds, etc: three-value logic. The test program that git bisect runs can return an exit value that means that the failure didn't happen, a different value that means that it did, or a third that means that it neither failed nor succeeded. I wrote up an example here:

https://speechcode.com/blog/git-bisect

Re:The Timeless 9 Golden Rules of Debugging by Noumenon72 on Monday January 13, 2025 @05:12PM (#42690156)
Very handy! I forgot about `git bisect skip`.