this post was submitted on 07 Feb 2024
2 points (100.0% liked)

Programming

4 readers
1 users here now

This magazine is dedicated to discussions on programming languages, software development, and coding. Whether you are a beginner programmer or an experienced developer, this is the place for you. Here you can share your knowledge, ask questions, and engage in discussions on topics such as coding languages, software engineering, web development, and more. From the latest trends and frameworks to tips and tricks for debugging, this category covers a wide range of topics related to programming.

founded 2 years ago
 

The value of a clean git history is often underestimated. I will explain one of the advantages based on the git bisect command.

top 4 comments
sorted by: hot top controversial new old
[–] kevincox@lemmy.ml 0 points 9 months ago* (last edited 9 months ago) (1 children)

bisect stands for “binary search commit”

Haha, that is a funny misunderstanding. "bisect" stands for bisect. It is a word. It means to cut in half. Because the command cuts the range of suspicious commits into two, then tests which half the problem started in.

to divide into two usually equal parts

https://www.merriam-webster.com/dictionary/bisect

But I guess it can be misread as BInary SEarch CommiT.

[–] danrot@kbin.social 1 points 9 months ago

I swear, I didn't come up with that myself, I read that somewhere else, but of course I don't have a source anymore 🙈 Maybe some git developer is a huge fan of wordplays?

[–] kevincox@lemmy.ml 0 points 9 months ago* (last edited 9 months ago) (1 children)

All of this can only work with a clean git history containing only working commits.

This isn't really true.

  1. You can use git bisect skip to skip commits that can't be evaluated. So if you are tracking down the failure of test foo and this commit fails to build, you can skip it.
  2. If all merged commits are green then you can use --first-parent to avoid testing inside a development branch. This way you can identify which merge caused the issue, even if other merges had broken commits.

So it is easier in general if you have all working commits, but it isn't necessary. Really as long as you have green history on your main branch you will be able to get good results without much effort. I would highly suggest using some sort of merge-queue based workflow to ensure that the master branch is always green.

I would generally prefer using --first-parent rather than forcing squashing. As smaller commits can be much easier to understand and the fact that commit IDs don't change when being merged can make it much easier to manage stacked PRs and hotfix backporting.

[–] danrot@kbin.social 1 points 9 months ago

I agree that some stuff is easier when not squashing commits, but for the teams I've been working with I've felt that the pros of squashing outweigh the cons, but of course YMMV.

But I didn't know about git bisect skip, thanks for the tip! But sincere question: What happens if there are e.g. three adjacent broken commits? If I have skip all three of those and the error was introduced in one of them, then git cannot tell me which commit introduced the error, right?