9 ms·
Squashing commits into one mega-commit isn't great for future investigations of the commit history (code review, bisects etc). It is much better to create separ
by pabs3 6y ago
Squashing commits into one mega-commit isn't great for future investigations of the commit history (code review, bisects etc). It is much better to create separate logical commits, rebase them and pull in the result, either as a branch fast-forward merge, or with a merge commit where appropriate.
- properdine 6y agoa year from now, are you actually going to want to test each individual change in a pull request, or are you going to want to test it as an entire unit? I agree that code review you want smaller units but my experience has been that 1-2 years later, you no longer care about the individual units and instead you want the entire patch/PR all together.
- dboreham 6y agoI think it's more about: in a year from now will you understand the purpose of a change to some code you're debugging? If the commit says "merged PR 2234", answer is probably not.
- pabs3 6y agoI definitely will want to do that, especially when bisecting a random bug that was introduced with one of the changes in that PR. The smaller the unit of change the better, as long as they are logically separate changes.
- pgaddict 6y agoI'm pretty sure you want reasonable meaningful commits. On tiny projects it may not matter, but on larger projects it's definitely a huge benefit, because chances are you'll have to investigate a bug in that code, re-learn why it was done this way, etc. And maybe bisect the git history to find which exact commit caused the issue. Which is why larger changes are often split into smaller patches that may be applied and tested incrementally. If you just merge the whole pull request as one huge patch / in merge commit, you just lost most of that.
- rectang 6y agoNirvana is: • Setting `merge.ff=no` in git config to force merge commits by default. • Creating a series of logical commits on `my-feature-branch`. • Merging `my-feature-branch` into `main` with a bona fide merge commit. • Using `git branch -d my-feature-branch` (NOT capital `-D`) to delete the feature branch safely and without worry, since `-d` only deletes the branch if the commits are present on HEAD. • Using `git log --oneline --graph` to see a clean representation of the actual history.
- pabs3 6y agoI would only use merge commits when it is appropriate, like a commit series porting usage of a dependency from an old version to a new one.
- rectang 6y agoWell, there are different views of "appropriate". When you do team development and everything is done via feature branches, it's nice to have merge commits so that the integrity of the each feature development effort is preserved via a merged branch in the history. If everything is flattened, it's harder to see where the branches (standing in for development initiatives) begin and end. You can't always get fast-forward merges anyway. Long-lived branches with merge conflicts are undesirable but unavoidable in the long run. At least some of the time, you're going to have merge commits even when your "appropriateness" test says there shouldn't be one.
- pabs3 6y agoDo you at least agree that merge commits for single-commit PRs aren't "appropriate"?
- rectang 6y agoI don't feel strongly about the issue. A good clean fast-forward merge of a single-commit PR is fine. But I've also worked at multiple jobs where every merge to the production branch created a merge commit and that's also fine. It adds a bit of complexity to the history graph, but it's not meaningless complexity. If your commit history is majority single-commit PRs then having additional merge-commits everywhere would be noisy, so in that case it would be too much. I don't tend to work on actively developed projects that match that pattern, though. Most feature development involves multiple-commit branches.
- earthboundkid 6y agoWhen someone invents the git killer, it will have a feature called “subcommits” that will be blindingly obvious in hindsight.
- renewiltord 6y agoYou get this by forcing merge commits for every non-single-commit change.
- urxvtcd 6y agoNot sure why you are being downvoted. You actually can use merge commits this way, by viewing the diff produced by git diff $merge_commit^...$merge_commit^2 when interested in whole change-set introduced by a branch or looking at individual commmits when interested in well, individual commits.
- earthboundkid 6y agoSure, you can use git to do this, but the git killer will have it as an expected capability. I also think that octopus merges are basically always a disaster because they can't be meaningfully reviewed and put your repo into an unknown state. Maybe there's some way to get the advantages of merge commits (preserve all history!) without the disadvantages (jumble all history!).
- WorldMaker 6y agoYup, and you can use --first-parent to git bisect, git log, git praise to interact at the "macro-level" of those merge commits by default, and dive in to the fuller graph only as necessary.
- oftenwrong 6y agoIf I've correctly understood what you mean, I've wanted this for some time now. A way to preserve history while adding a single, linear integration of changes.