7 ms·
The approach that has worked best for me is pretty simple. Master should always be in a deployable state. Any commit that lands on master must include unit te
by simonw 7y ago
The approach that has worked best for me is pretty simple.
Master should always be in a deployable state.
Any commit that lands on master must include unit tests that demonstrate that it works (or at least doesn't break anything).
Incomplete features that will take more than a week or so to develop should be merged to master early protected by feature flags. This avoids long running branches.
I like squash commits: build a feature iteratively in a branch + pull requests, squash to master once it has the tests and documentation bundled together with the implementation. This gives you linear history.
People who prefer to review smaller commits can do so in the pull request - it's only the finished item that gets squashed into a larger commit.
- zabil 7y ago> Master should always be in a deployable state. +1 to this and squashing commits. I'd even go far as saying trunk based deployment model over trunk based development. This can be done via Pull requests or short lived branches. I prefer having all the context, discussions and testing added to the pull request. Even setting up environment per pull request. It's much easier to track and get feedback.
- shock 7y ago> [...] unit tests that demonstrate that it works I'm going on a bit of a tangent here, but unit tests don't demonstrate that it works – acceptance tests demonstrate that it works. Unit tests help reduce the time to narrow down problems and in some cases help with refactoring (if refactoring is limited to the inside of methods).
- arialdomartini 7y agoI personally don't squash commits and loose information. I see the value in having a compressed view of the log history, but in that case I use git log --simplify-by-decoration
- anandsuresh 7y agoI agree with this approach. It worked beautifully for me at my last job. Keeping master ready to deploy is the way to go, along with squashed commits for a linear history. A side-effect of this approach is that it makes it super easy to bisect your way should a regression occur; something that I've found is impossible with GitFlow.
- retreatguru 7y agoWe use this work flow and it works masterfully. I have no need to save all my small commit - partly because I commit often to run tests in parallel on a CI server. Does anyone know of a layer that you can use on top of git to make the occasional squash and rebase easier? I know gitless is a helpful layer on top of git but not sure it support this specifically.
- noahtallen 7y agoI mean, GitHub allows you to squash merge a PR, which is what we do at work. I find it really simple to summarize everything in the PR in that squash commit that ends up on master. I only rebase/squash locally if I need to make it easier for review
- tremon 7y agoCan you still easily bisect to find which change broke a certain feature? I usually recommend against squashing because it's easier to identify an error in a 10-line diff than in a 2000-line diff.
- e_proxus 7y agoThe problem is more the state of the rebased commits. If it is a dirty history, bisect will break for a myriad of random reasons (broken tests, incomplete features etc.). So if you don't squash, and want to run bisect, you _have_ to ensure that all commits are clean and working. Easier said that done.
- u801e 7y ago> So if you don't squash, and want to run bisect, you _have_ to ensure that all commits are clean and working. Easier said that done. It can be done if the commits are separate logical units of work rather than work in progress commits. One approach I take is to take the diff between your branch and master, make a new branch based off of master and stage parts of that diff (parts that make a logical unit of work) and make a commit out of it. You can do that with commands like git apply with the relevant diff hunks. Then, to test whether each commit works, you can run git rebase --exec "your-test-commands" master and it will apply each commit in your branch and run the test commands. If they fail, then you can fix the issue in that commit and run git rebase --continue to move onto the next commit. This way, you can get a logical set of commits where each of them are in a working state.
- jacobwilliamroy 7y agoI feel really good when I completely destroy my application and then roll back to the previous working version. It's such a thrill, man.
- gouggoug 7y ago> I like squash commits: build a feature iteratively in a branch + pull requests, squash to master once it has the tests and documentation bundled together with the implementation. This gives you linear history I disagree with squashing commits when merging to master, here's why: Your commit history is what you will use later down the line (think 6 months, a year, 2 years later) to find a very nasty yet incredibly subtle bug in your application. Imagine said bug was introduced by a feature that took about 1 full month to code, introducing 1000 lines and removing 500. That feature was probably made of many small commits (say, 25 commits total), on a feature branch called "super-feature". If your developer cared at all about making "atomic" meaningful commits, each one of those commit will be introducing a small very well defined subset of the entire "super-feature". The "super-feature" will in the end be the result of all of those commits together. Squashing that history of 25 commits, will create one giant commit of 1500 changes. Have fun finding where in those 1500 changes that little nasty bug was introduced! Instead, if you hadn't squashed, you simply use `git bisect` and find in no time that the bug was introduced by the 12th commit of that branch, which itself was a small commit of 1 little change: diff --git a/statistics.php b/statistics.php index 69e435aa9f..46666daa93 100644 --- a/statistics.php +++ b/statistics.php @@ -8,7 +8,7 @@ - a = b + c + a = b - c If you want a very linear history, enforce a: git rebase master super-feature git merge super-feature --no-ff This will rebase your branch on top of master, but, when merging, the `--no-ff` option will tell git to create a merge commit. This merge commit will make it very clear that the code branched off and was later merged back into master, yet, it will keep the history linear. ======= TL;DR: Your commit history is as important as your code! Don't squash it away! I wish github never introduced that feature and instead developers were taught how to create a meaningful history of commits. =======
- nickysielicki 7y ago> Your commit history is what you will use later down the line (think 6 months, a year, 2 years later) to find a very nasty yet incredibly subtle bug in your application. No, it won’t. If I didn’t catch it then, I will have to read the code and understand it and spot it. At work, where my builds take anywhere from 30 minutes to 3 hours depending on the target, your git bisect on 1500 commits represents days of building and testing. Or I could just read the code again. Commit messages should provide context for going through the process of rereading the code, and little else. If a commit message literally describes what the code does (“change constant from X to Y”), it’s self-describing and unnecessary.
- Silhouette 7y agoMaster should always be in a deployable state. Isn't that what the develop branch in Git Flow is for? Your project might need some additional steps as part of its release process, and those can take place using the corresponding release branch, but the idea is that you can start a new release off develop whenever you want. I like squash commits: build a feature iteratively in a branch + pull requests, squash to master once it has the tests and documentation bundled together with the implementation. This gives you linear history. Indeed. We're talking about using Git. Even if you're using a Git Flow style of workflow, why wouldn't you regularly rebase any feature branches back onto develop if they're lasting more than a short time, so you are keeping up-to-date, and why wouldn't you squash the finished feature down to a single commit that can be fast forwarded onto develop when it's ready, to maintain a linear history with one commit for one significant feature or fix? The only time I've seen non-FF merges in a Git Flow style project is for bug fixes on release branches, but those tend to be characterised by two key properties: they are relatively simple and relatively important. If it's not simple, you probably need to abort that release and go back to your main development line to do whatever more substantial work is required before continuing, then make a new release. If it's not important, you probably ship that release with the known bug, and the fix gets made on the "develop" branch via the usual process for incorporation in future releases. So the effort involved in merging bug fixes from release branches back to develop is typically both relatively small and well justified, and if you do need any manual conflict resolution, that implies divergence since the point when the release branch was started and then it probably is a good idea for someone to take a more careful look and make sure the bug is properly fixed on develop as well.
- amscanne 7y ago> Isn't that what the develop branch in Git Flow is for? Your project might need some additional steps as part of its release process, and those can take place using the corresponding release branch, but the idea is that you can start a new release off develop whenever you want. In gitflow, “develop” is master. The master branch serves no real purpose. The intent of “master is always deplorable” is really that every commit, on every branch is deployable. To me, this is the whole point of CI. Commits need to be restructured in such a way that everything works incrementally, otherwise you’re asking for trouble — how do you even bisect problems?
- westoque 7y agoThe fact is that this doesn't work for everyone. What we found to be most workable is master is always "stable", then we have a production branch that is cut from master. This gives you a few things: 1. More predictable deployments (let's deploy every week with X items) 2. Better rollbacks (rollback to last production deploy instead of guessing SHA1 of last acceptable state)
- simplyinfinity 7y agowe deploy to test multiple times a day from out master branch after a Pull request is reviewed & merged. the deployment bundle (zip of the state of the code) that goes to test later goes to staging and production is the same across environments. The only thing that changes is the configuration variables which are replaced at each env. This ensures predictable deployments and if we want to rollback we just pick the last release bundle and re-deploy that.
- bfung 7y agoMy snarky version of this is: ideally head of master is deployable (no regressions, yadda yadda). In reality, how many times has head master of master been broken and one had to rollback, and then had to scramble to find the rollback? Gitflow is fine - better to use it (w/the girl extension) than spend time arguing branches.
- legulere 7y agoHaving to frequently rollback changes can be argued to mean that you don’t do enough testing before merging but are testing in production.
- gardnr 7y agoThe method you describe is functionally the same and only nominally different. It could be said: > What we found to be most workable is develop is always "stable", then we deploy from master.
- debaserab2 7y agoThis is what I use tags for. Master = deployable state (stable) Every deploy gets a tag (named with its version). Rollback to previous tag in event of failure. Deployments remain just as predictable.
- bArray 7y ago> Master should always be in a deployable state. I think the head of master should always be deploy-able, but ultimately it seems better to make use of tagging of specific hashes which realize some degree of reliability for field use. Obviously you have your unit tests and other kinds of tests, but ultimately nothing beats just using it. If it "feels" reliable (which can be hard to quantify sometimes) or has proven itself (you've been using it without issue for some time), then it's probably worth tagging for that fact. > Incomplete features that will take more than a week or so > to develop should be merged to master early protected by > feature flags. This avoids long running branches. I prefer to properly scope the time/effort required to complete a feature, rather than having massive features. If a feature is taking more than a few weeks to bring into fruition (assuming ~1 dev per branch), then it's probably too large of a feature and needs to be broken down. A properly sized feature should probably fit within a sprint cycle.
- Silhouette 7y agoI prefer to properly scope the time/effort required to complete a feature, rather than having massive features. If a feature is taking more than a few weeks to bring into fruition (assuming ~1 dev per branch), then it's probably too large of a feature and needs to be broken down. A properly sized feature should probably fit within a sprint cycle. Ideally, I agree, though this does depend on what your business requirements are. Some features are just fundamentally complicated, and it might not be possible to implement the feature itself, or even decompose it into meaningful parts that can be implemented, in one short round of work. Fortunately, that doesn't happen very often for most types of development work!
- bArray 7y ago> Some features are just fundamentally complicated, [..] > Fortunately, that doesn't happen very often for most types > of development work! Every problem should in theory have some of breaking it down, otherwise we have no hope in programming it. We should be able to break it down far enough that it can be reasonably sanity checked. If the feature is too complicated then you're asking for bugs. From an objective/goal stand point, we also need some way to measure our progress and be able to evaluate whether a pivot is required. It's very easy to get stuck in a problem for a long time if we have no external measure.
- projectileboy 7y agoYes yes yes. Different teams have different needs, of course, but what you described should be considered the default workflow.
- fulafel 7y agoNot far from my experience. I advocate preserving history, and wisdom of requiring unit tests for everything depends on project properties. I think this is a good treatment about why rebasing is bad: https://medium.com/@fredrikmorken/why-you-should-stop-using-git-rebase-5552bee4fed1 https://medium.com/@fredrikmorken/why-you-should-stop-using-...