9 ms·
Stop cherry-picking, start merging, Part 1: The merge conflict
- shagie 8y agoStop merging if you need to cherry-pick https://blogs.msdn.microsoft.com/oldnewthing/20180709-00/?p=99195 https://blogs.msdn.microsoft.com/oldnewthing/20180709-00/?p=...
- fjsolwmv 8y agoThis is the answer for anyone who isn't maintaining something like Windows, with multiple versions of product simultaneously for years. If you are cutting releases of a web service, cherry pick into short lived release branches.
- deleted 8y ago[deleted]
- zamalek 8y agoI agree. If you need to move a fix into multiple branches, isolate that fix in its own branch to begin with. The entire branch is the cherry. Each target branch deserves its own merge because chances are, seeing as the thing is so critical, the merge needs adequate attention each time to get done correctly (causing more work and friction is sometimes healthy). If you're reaching the end of your sprint and your branch isn't ready to merge, chances are the entire branch could use another sprint in the oven. You've completely run out of time and you want to isolate a few changes, that's great if you want to move fast and break things. In TFVC (and SVN, CVS, Perforce, etc.), branches are expensive. It has taken me months to "unteach" people at work antipatterns that arise due to that. Management still doesn't get it - there is this holdout perspective that branches have to be micromanaged. This was the only sensible way to manage the mess caused by TFVC+co. If you're finding unusual degrees of friction with Git (Mercurial, Bitkeeper, etc.), chances are that you're artificially introducing issues caused by your legacy version control and trying to solve them. Start forgetting and unlearning.
- sourcesmith 8y agoSVN branches are not expensive. They use a copy-on-write. http://svnbook.red-bean.com/en/1.8/svn.branchmerge.using.html#svn.branchmerge.using.create http://svnbook.red-bean.com/en/1.8/svn.branchmerge.using.htm...
- deleted 8y ago[deleted]
- HelloNurse 8y agoGood luck using hard links on Windows without accidents. Apart from sarcasm, SVN branches use suffer-on-merge: creating a branch means immediate technical debt of the most useless kind, which is more expensive than any inefficient file copying. From the same manual: "To perform a sync merge, first make sure your working copy of the branch is “clean”—that it has no local modifications reported by svn status." "One special kind of flexibility is the ability to have a working copy containing files and directories with a mix of different working revision numbers. Subversion working copies do not always correspond to any single revision in the repository; they may contain files from several different revisions."
- zamalek 8y agoEvery SVN branch costs money, any system that cares about branch ancestry is expensive. If me and Jim are working on two features on the same release and then I find that I need to integrate Jim's work in order to continue mine, Jim will need to merge his [incomplete] work into a common ancestor. If I am working on a feature in a completely different release, this "merge path" gets long and begins to cost money and carry risk. Jim hasn't finished his work yet; before any release can happen, Jim has to finish his work and merge the complete changes to all affected branches. If we can't wait for him to finish, then we're rolling back his changes and, oops, someone rolled back the same change on multiple branches. Now we can't launch a hundred features because there was an interdependency between two.
- doombolt 8y agoMerges is the stupidest thing there ever is in the land of source control. Contrary to the author I struggle to find even a single use that would make merge merited. My main point is that merges are not easily computable. comm3 = merge(comm1, comm2) is not a kind of function you can run and see for yourself. Instead it is a kind of hand wavy magic in which we declare that those two apples plus a lemon equals three mangoes. You throw the beauty of hash tree out of the window like an overdue christmas tree.
- wodenokoto 8y agoWhat's the alternative? Only work on master and only on one document at a time?
- mkesper 8y agoRebase everything so you get a clean timeline without meaningless "merge of bla" commit messages. Can be made mandatory by turning your repo fast-forward-only.
- domlebo70 8y agoIsn't that just a merge, but done one commit at a time?
- doombolt 8y agoNo it is not, because there is no mystic handwavy commit involved. You just apply a patch basically. Much less this handwavy commit exposed to uninterested parties.
- jamietanna 8y agoGP's comment was that a _rebase_ is a merge, one commit at a time, due to replaying each commit over whatever was there. Although you still fix the conflicts each time, it means you don't have many merge commits as you go along
- fouc 8y agoI only cherry-pick when it's the only commit of a feature branch that's going to be removed anyways. If development continued in that branch, I would merge master back into the feature branch again, or rebase the feature branch on master. Not sure why, but I always knew from the beginning that cherry-picking is something not to be done from a live in-development feature branch without taking steps afterwards.
- LolNoGenerics 8y agoStop excessive branching if you can use feature flags.
- pjc50 8y agoThis is only a good idea if the things you're working on are isolatable "features", and you have an explicit process for garbage-collecting old feature flags. Otherwise the combinational explosion of possible flags kills your testing over time.
- alangpierce 8y agoIn addition to flags for functional changes, I'd say "design refactors to be incremental". It takes some care and thought, but almost every refactor I've seen can be framed as small steps that can each be immediately integrated into master. For example, when porting code from Python 2 to 3, you can change individual files to be 2/3 compatible until the whole codebase is, then flip the version without touching the source code, then get rid of 2/3 compatibility code. This tends to be safer and more reviewable than trying to rewrite the world on a separate long-lived branch and then land it all at once.
- rjmunro 8y agoI would normally rebase the feature branch onto master if I need fixes from master and no one else is working on it. Usually this is the case - one developer works on each feature in a feature branch until it becomes a Pull / merge request and gets commented on and eventually merged. I will sometimes make a fix in a feature branch that should go onto master before the feature is ready, and cherry pick it to a new bugfix branch. Once it's merged, if you rebase the feature onto master git will normally sort it all out, or you can use rebase -i to skip the cherry picked commit manually.
- jillesvangurp 8y agoRebasing is great for branches you haven't pushed that nobody else is working on. For that case, definitely rebase before you push. If that is not the case and you have previously pushed your branch somewhere remote already, rebasing would end up rewriting history and things get a bit more tricky. You can still get away with this if it is just you. Now here comes the crux: if you have a branch that you've been working on for several days, you really should be pushing it regularly to remote so that you don't lose your work. Also you should be creating lots of small commits and create a giant commit that touches everything. So if you then go and rebase, you are potentially rewriting history for someone. If that is at all going to be an issue, the better solution is to create a new branch and push that (or for Github folk, create a new pull request). Many bigger projects will be configured to flat out reject rebased histories overwriting existing ones. Most of the public projects only allow you to create pull requests that have to be accepted by someone with commit rights on the main repo. And many of those people prefer clean rebased histories when they are merging so that they can do a so-called fast forward merge where the history stays nice and linear. If you have a branch with lots of back and forward merges, that is likely not going to go down well. It makes reviewing a lot harder and you may be better off creating a new branch and then rebasing the old one on top. Typically you'll have a bit of work re-solving all the conflicts you resolved earlier. This is a good argument against long lived branches. Cherry-picking is sometimes useful but it potentially creates issues for the subsequent merge (fast forward or not). The nice thing with the pull request model is that it is not the problem of whomever cherry-picked but only that of whomever created the branch. If there is a conflict, it would be theirs to sort out before they can get their PR merged. If you are cherry-picking small fixes, this is usually not a big issue and a perfectly valid way of solving a small issue without landing a lot of work in progress.
- drewg123 8y agoThis gets more complex when you have, for example, a volatile open source codebase as an upstream. At work. we regularly merge upstream FreeBSD into our codebase, and run a suite of tests to make sure that we have not introduced a regression in performance or functionality. These tests take days to run, and roughly another day to analyze. What causes a cherry pick is if we realize late in our release process that we're suffering from a bug that was fixed upstream (or that we can fix upstream). Since we're late in the release process, we don't want to take a full sync to the tip of the upstream master and consume potentially unstable changes, as that will mean re-running all our tests and resetting the clock on the release. So we cherry pick the fix (sometimes after committing it upstream ourselves).
- danieldk 8y agoOut of curiosity. What are you working on? A derivative of FreeBSD?
- drewg123 8y agoThe Netflix CDN. We run a slightly modified version of FreeBSD.
- deleted 8y ago[deleted]
- peterwwillis 8y agoIs this just the kernel, or the OS as a whole? This is probably a redundant comment, but maintaining a fork of a vendored product kind of defeats the purpose of using the vendored product. If at all possible I would recommend either to use the vanilla release, or fork it once and stop integrating. If you were shipping your custom FreeBSD to customers, and they were relying on it being FreeBSD plus your changes, I can see integration providing significant value. But since it's for a CDN, it's probably only being used by your team.
- mariusmg 8y agoAre you working on the PS4 OS ?
- sourcesmith 8y agoLooking through the comments, seems like stacked diffs would serve better in a lot of these cases...
- alangpierce 8y agoSome background on stacked diffs in case people aren't aware: https://medium.com/@kurtisnusbaum/stacked-diffs-keeping-phabricator-diffs-small-d9964f4dcfa6 https://medium.com/@kurtisnusbaum/stacked-diffs-keeping-phab... I've been using stacked diffs for years now after trying various other git workflows, and I love the freedom it gives me. I almost always structure my work as a single branch (not a separate branch per feature), one commit per code review, and I'm free to edit, reorder, split, and combine changes as I please (mostly with interactive rebase). When a commit gets accepted, I just move it to the bottom of my stack (if it's not there already) and push it. It makes it easy to split changes into a "pipeline" of logical steps that can each be independently reviewed and landed, with multiple steps in code review at once. I hate it when people treat dependent code reviews as an "advanced feature". They're only advanced if you make your workflow so advanced that they're hard to keep track of (many commits per review, many branches, merge commits). If you keep it simple (one commit per review, always rebase), that simplicity gives you much more power in other areas that IMO are more important. I just wish it wasn't so much of a pain to get working in GitHub.
- fulafel 8y agoStacked diffs seems to be a rebase based workflow, so it has many of the same drawbacks as cherry picking.
- Sir_Cmpwn 8y agoYou should only use merging to merge two divergent or unrelated histories. Merging should be a tool you use infrequently. GitHub has trained you to do it wrong.
- elcomet 8y agoWould you care to add more details? Are you saying that id you use some workflow like one branch / one feature, you should usually rebase? Almost all branches have related history, it is very rare to have completely unrelated branches with separate starting points.
- Blackthorn 8y agoGithub is respecting the original intention of git. For a long time it didn't even have cherry-pick functionality.
- Sir_Cmpwn 8y agoCitation needed. So far as I can tell from reviewing git's source code, cherry-pick was there since at least September 2005, after which the trail runs cold because of a big refactor. Git's first release was in April 2005.
- akerl_ 8y agoWhy wouldn't I want to merge?
- Sir_Cmpwn 8y agoIt makes a merge commit which is usually unnecessary. If there were no conflicts, there's no need to have a commit fixing them up. If you just want to know who integrated the patch, git stores the author and committer fields separately. Most git users in touch with the design goals of git use branches sparingly, either for long lived projects (with hundreds of commits) or as a sandbox in which work is frequently rebased into a concise history of a few patches, which are usually integrated upstream without a merge. Merges are also used to merge disparate trees, like when Linus merges in trees from around the kernel development scene (since each kernel subsystem maintains their kernel tree as almost independent projects, using merge makes sense to integrate the foreign histories into the upstream kernel). The Linux kernel approach probably requires a full-length article to fully explain, though, so don't read too much into that.
- jdlyga 8y agoHow else do you get bugfixes onto a release branch when the main develop branch has already moved on? Should you rebase your feature branch on the release branch instead, then merge it?
- bluejekyll 8y agoExactly. This article seems to not really discuss that case. It’s specific to feature branches off a master line. Git rebase is generally what I use in feature branches. Cherry-picking is important in the case that you mention, master to release, the opposite direction could be a merge, ie release branch to master.
- joevandyk 8y agoBranch off the release branch for fixes to it. Then merge back into release and develop branch.
- jdlyga 8y agoBut what happens if it's a fix that was made to master. Then later, the boss decides that they need that change as a bugfix to the current release? How do you accomplish that without cherry-picking? Do you rebase the feature branch it was a part of and merge it?
- servilio 8y agoThey explain that in part 3, direct link: https://blogs.msdn.microsoft.com/oldnewthing/20180314-00/?p=98235 The technique is not new, in the Monotone wiki it is known as daggy fixes: http://wiki.monotone.ca/DaggyFixes/
- neogodless 8y agoDoes anyone have any references / recommendations along the vein of "guide to branch strategies" for certain development methodologies? For example: working in sprints / AGILE, branches for testing/QA/user-acceptance environments, etc? (While I would hope the answers to this question would be widely useful, I mostly work on C# applications, with less focus on JavaScript-based applications. Maybe that's relevant for deciding on strategy - hopefully not!)
- alkonaut 8y agoI'd argue that language is less important than product/deployment type. The difference between releasing e.g. a desktop product on a yearly schedule with maintenance fixes going both to the 2018 and earlier main releases, versus building a web service with a single deployed version deployed perhaps several times per day is rather big when it comes to a branching strategy.
- WorldMaker 8y agoThe most commonly referenced references to read can be found by searching for GitFlow (heavier) and GitHubFlow (lighter). Personally, I recommend the GitHubFlow and CI/CD for "agile", and never branching per-environment but there are almost as many opinions as there are developers.
- draw_down 8y agoHmm, I find cherry picking much easier to reason about than merges, but to each their own I suppose.
- spenrose 8y agoWonderful general Git resource: https://github.com/k88hudson/git-flight-rules https://github.com/k88hudson/git-flight-rules
- gnufx 8y agoThis sort of discussion makes me even more grateful for patch-based systems (Darcs, and possibly Pijul) than does having to use git for apparently simple tasks required to make contributions to things.