Merging vs. Rebasing
atlassian.com
atlassian.com
If you work on a sizeable team with code review before merge workflow, the tip of the repository will be moving faster than is pleasant or safe to rebase, and every so often, commits will exist in multiple different branches (in order to prevent blocking development pending a code review). You do not want to be rebasing commits such that they appear in multiple different branches with different hashes etc. It's a recipe for pain. And being blocked until code is reviewed and merged is hardly more productive.
Even working like this, git bisect works just as well to find a commit, and git log on an individual file works just as poorly as it always does (e.g. changes in merge conflict resolution are hidden by default).
Rebase if the commits only exist in your local repo. That's fine. But no more.
BTW some teams do prefer a rebase workflow and we want to support them in GitLab too, showing a diff with the changes in an MR if the commit was overwritten
I go back and forth on this issue.
On one hand, I like having commits that do one thing. Makes it easier to "read" a project's history, to revert things, to track down bug introductions.
On the other hand, I like having a history of the mess of how I actually implemented something, because it's more accurate and more detailed, both of which help when I go all DETECTIVE-MODE: ACTIVATE.
But on the other hand, the mess often includes such uselessly awful commit messages, and lots of terrible code that only existed for like 2 hours until I realized it was the wrong way to do it, and scrapped it. That's kind of a red earring.
So I don't really have a firm opinion on it anymore. I just go with whatever I feel that day. That said, I'm a team of 1 and have been for about 4 years, so it doesn't matter too much in my case.
The "mess of how things were implemented" has 0 value for your fellow coworkers when it comes to understanding the code and tracking down bugs.
Each and every commit should as much as possible be "atomic" with a clear message describing what was done (not the how) and why.
It is in the commit message that the developper should go on explaining their implementation decisions.
What I picture is a feature branch with multiple small commits leading to the full implementation of the feature. When comes the time to rebase and merge in master, the merge commit could include a detailed explanation of the implementation choices that were made.
> I'm a team of 1 and have been for about 4 years
What kind of work do you do?In our continuous deploy environment, we're a revert first ask questions later shop. That means when we find something wrong we revert, and that happens a lot. Since we revert so often it is ESSENTIAL that history is clean. Sometimes your code is reverted before you have a chance to be consulted. It always sucks, but if it happens you want to be sure that your change isn't only partially reverted.
I think Facebook uses a souped up version of this strategy (based on how I interpret their presentation on it anyway). It seems like the engineer ships off a commit, and then it goes into a review branch where it gets automatically rebased against master continuously while waiting for review. When it passes review it goes onto master as the newest commit -- if a conflict happens before the review completes or during the final rebase then the engineer is notified to resolve the conflict and push again -- I think review needs to happen again in this case -- but it makes sense to do so as the first review was done without awareness of the change that caused the conflict ... I'm sure I don't describe their actual process accurately but I think it something along these lines ...
I haven't personally really noticed any downsides with that approach, can anyone else think of any?
2. Pull master just before you push.
3. If there are new commits, rebase onto master again.
If everyone on the team follows these 3 rules, it won't get too messy to untangle.
There's an xkcd about this I think.
:-)
When I started using git I remembered feeling overwhelmed by rebase because with a merge you only resolved conflicts once, whereas with a rebase you had to continually fix conflicts without knowing when it would end.
It took me a while to finally understand how rebase properly worked and I can finally use it correctly now.
As for the example of a "linter" commit, I feel that lends itself more naturally to teaching git commit, git commit --amend, or rewriting history. Which the OP is not about.
Anyone reading something like this as a newcomer is free to go on to become an expert and for their own opinions and practices. For an experienced practitioner to read a "Tutorial" and deem it dogmatic because it doesn't adhere to their specific and experienced approach ignores the fact that the practitioner has the benefit of significant experience that a new learner does not.
Not necessarily. I understand rebase, but it is often a much more complex operation than a marge, and for (often) little gain (cleaner log). So it's a tradeoff. When the team is small enough that log pollution isn't too much of an issue, it's not worth rebasing, IMO.
I use the rebase flow on my solo projects as well as advocate for it on large teams. Even (especially) when it's just me, having a tidy history saves me tons of time; especially when I'm prone to constant distraction by business-y things.
Edit: s/I/I'm/
Where can I find the "code of conduct" for HN?
The comment complains that the article provides nothing new and is feeding the rebase-vs-merge holy war. I would disagree with that, and it suggests to me the commenter didn't read the article. It's usually considered bad form to make comments on the headline without reading the article. This article in particular steers clear of all the holy war aspects of the rebase-vs-merge debate. I didn't downvote, but I speculate that's why it got downvoted.
In the HN FAQ is a link to guidelines: https://news.ycombinator.com/newsfaq.html https://news.ycombinator.com/newsguidelines.html
One of which is "Please resist commenting about being downvoted. It never does any good, and it makes boring reading." which is why you'll rarely see discussions about downvotes, and why usually speculation is all you get. ;)
I'm not complaining that it's feeding the holy war, just pointing out that it is one. My complaint is that we try to solve these issues with dogma, rather than expecting everyone to have a strong understanding of git, at which point all of the problems just sort of stop happening.
I've seen the holy war too, and I was impressed that this article took special care to stay completely out of it. I didn't see any dogma at all in this case, I saw helpful suggestions educating people about git and about when to make the call.
It isn't helpful in any discussion to just say "side X are afraid and stupid.", and especially not without a good justification.
No-one has (I believe) ever thought "Oh wow, I didn't realise I was being afraid and/or stupid, thanks for telling me. Now I'll change sides".