Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Agree with the thoughts on atomic and meaningful commits (though would drop the merge commit entirely), and I will rebase my commit history extensively at times to get it into a presentable state along the lines listed here.

Bottom line: the history, content, and message of each commit, in addition to the resultant repo state, are all artifacts of your work and are worth shaping and crafting in order to optimize for communicating to yourself and your fellow developers in the future.



> though would drop the merge commit entirely

The merge commit is important though. It helps delimiting a set of commits that have meaning all together from the rest of your commit history. Here's an example:

  a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k 
In the history above, did you notice that commits c through h are actually related to one another? They were introduced a while ago by a feature branch.

Compare the previous history to this:

          c -> d -> e -> f -> g -> h 
  a -> b /                          \ i -> j -> k 
Now that's very clear that c through h are part of the same line of work. All those commits were probably part of 1 single pull request and were reviewed in the context of one another.

My history here is still very linear. Yes, there's 1 little branching off, but that's all.

At my previous company we had a codebase of well over 20k commits entirely made of those little branches branching off master, then merging back in. It made it for an incredibly readable history.

An other added advantage of not removing the merge commit is that you can revert the entire merge of your branch in one go.

Without the merge commit, you need to remove each commit one by one (and that's granted you remember which commit was the first one and which one was the last one).


Agreed your history is still linear. But I would suggest your merge commits are perhaps more trouble than they are worth. In commit sequences we prefix almost all commit subjects with the JIRA ticket ID, so the sequenced tickets are quite clearly marked as being related to each other without incurring the merge commit cost.

As for reverting merge commits, I'd rather not personally have to remember the rules as to how to re-apply after the revert (revert the merge revert, then merge the branch again)[1], let alone working on spreading that knowledge losslessly across the organization. This is admittedly something I haven't done much of, but I'd rather revert ~3-9 individual commits, squash the reversion commits (usually with a bit more context on why we're reverting), and push. And it could be scripted. I haven't made a script for it as it doesn't happen that often, but between using rev-parse and a sed script in the GIT_EDITOR environment variable it would be pretty quick.

Having merge commits also means that you have to teach everyone how to view diffs of merge commits, which admittedly isn't that hard, but it is still just one more barrier to know/teach/overcome, and the default behavior of showing a zero-line diff for a no-op merge commit doesn't help.

[1] https://mirrors.edge.kernel.org/pub/software/scm/git/docs/ho...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: