News for hackers. Stuff that matters.
Re:Commits are snapshots not diffs (2020) by TheLocehiliosan on Thursday April 08, 2021 @03:14PM (#26742564)
What you need to understand is people use rebase on their unshared branches. It's part of crafting your commit history to be a coherent set of atomic changes instead of the path you took while developing it all.

You rebase BEFORE you merge into the mainline branch.

Re:Commits are snapshots not diffs (2020) by fshbbdssbbgdd on Thursday April 08, 2021 @03:23PM (#26742666)
Do you run your test suite against each of the commits you create when rebasing? If not, isn’t this “coherent set of atomic changes” misleading? It seems like a lot of effort to make a fake clean-looking history.
Re:Commits are snapshots not diffs (2020) by breischl on Thursday April 08, 2021 @03:48PM (#26742942)
When I've done this, your private/dev branch may be a series of broken commits. Then you rebase onto main, squash to one commit, and test (if necessary). So what shows up on the main branch is a single, squashed, tested commit that contains one logical unit of code (usually a feature or fix).

In this model the main branch history is "real" in that it records the sequence of changes to the production code. It's "fake" in that it doesn't record the exact sequence of fumbling steps and backtracks you took to get there. But IME the latter is usually not very useful anyway.

Re:Commits are snapshots not diffs (2020) by fshbbdssbbgdd on Thursday April 08, 2021 @03:54PM (#26743004)
I like the squashed commit approach. I get there by merging upstream into my dev branch when developing, then squashing before I merge my changes into the upstream. As far as I can tell, that has the same outcome as rebase with squash. Both approaches create a simple commit graph, and both avoid fake intermediate commits.
Re:Commits are snapshots not diffs (2020) by xoudini on Thursday April 08, 2021 @04:04PM (#26743114)
In some cases I agree, but squashes can end up so large that doing a `git bisect` (which is quite useful in finding the comparatively small commit which introduced a bug) becomes unfeasible.
Re:Commits are snapshots not diffs (2020) by xoudini on Thursday April 08, 2021 @03:41PM (#26742844)
There shouldn't be an issue in doing so. During a rebase you'll either have no conflicts — in which case there isn't an issue — or you'll have to stop to resolve conflicts, and you might as well run tests before continuing the rebase. In both cases I'd argue that the statement "coherent set of atomic changes" applies.
Re:Commits are snapshots not diffs (2020) by fshbbdssbbgdd on Thursday April 08, 2021 @03:51PM (#26742969)
Correct me if I’m missing something here - but a lack of conflicts during rebase only means that the few lines surrounding your changes weren’t changed in the upstream. The rest of the repo changed, and this will often cause some kind of inconsistent state. I’ve encountered this situation frequently when using git bisect.
Re:Commits are snapshots not diffs (2020) by xoudini on Thursday April 08, 2021 @03:59PM (#26743060)
When you rebase, you basically replay the history of your branch since it diverged from the branch you're rebasing onto. Thus, the branch is always in a consistent state (or equally consistent to when you originally authored the commit you're replaying). And of course this assumes the target branch is already in a consistent state.
Re:Commits are snapshots not diffs (2020) by fshbbdssbbgdd on Thursday April 08, 2021 @04:38PM (#26743483)
If the upstream is like this:

A -> B

And you branch off B and start making changes, then the upstream continues on its own:

A -> B -> C -> D

Now you rebase your dev branch off D. Your changes get replayed on top of D and create new commits. Some of those commits might not be valid, because they take code that worked in the context of B and put it in the context of D. The history seems clean if all you do is look at the diffs, but if you bisect and try to use the repo in one of the rewritten commits, you may find it doesn’t even compile (even if that commit was fully functional before rebasing).

Re:Commits are snapshots not diffs (2020) by xoudini on Thursday April 08, 2021 @05:04PM (#26743729)
Hm, you're right. The simplest example I could think of right now is the upstream having renamed/deleted something that the dev branch depends on, but didn't directly touch. That would definitely cause a "broken" history during the rebased commits, and is technically unavoidable.
Re:Commits are snapshots not diffs (2020) by fshbbdssbbgdd on Thursday April 08, 2021 @10:49PM (#26746186)
A surprisingly common occurrence is two developers independently notice and fix the same problem, but they implement the fix in two different ways. The diffs might not conflict at all during a rebase. Or they might only conflict in some places, and the “behavioral conflict” remains after the diff conflict is resolved. This issue would eventually be noticed and fixed when tests fail before merging to master, but the intermediate rewritten commits are unlikely to be fixed.
Re:Commits are snapshots not diffs (2020) by xoudini on Friday April 09, 2021 @06:24AM (#26748726)
I can see this happening, but with a reasonable bug-tracking solution in place and enforcing `fix/...` branches for fixes, these situations could mostly be avoided.
Re:Commits are snapshots not diffs (2020) by Solvitieg on Thursday April 08, 2021 @06:15PM (#26744493)
For sure, I understand that.

It tends not to be an issue when a developer is working on an isolated feature that only he or she cares about, that is reviewed in a timely matter, and gets directly committed to main.

Often this is not the case.