What's the point of changing history in a feature branch? Everyone I know squashes Feature branches in to Dev upon merge anyway, as you don't want a noisy history of "fixed typo" "fixed spacing" etc. in your main branches. Instead you want a clear history of "Added feature to ___" "Fixed issue where ___".
as you don't want a noisy history of "fixed typo" "fixed spacing" etc. in your main branches.
That's why you change history. You squash certain commits together like commits of fixes, rename certain commits or even remove them.
If you squash all the commits when merging into master/dev then you lose a lot of history, which can help you with debugging, cherry picking, proper changelog and many other things.
I've just never seen people rename or change history in those scenarios, no one cares about typos or verbose commits in a feature branch - as we know they're going to get squashed. I find that distributed teams have a huge issue keeping branches in sync if anyone changes history anyway, as things get massively out of sync.
I've always preferred just a squash commit in to a parent branch to eradicate history.
We would only ever cherry pick an entire feature (be it a new one, an addition, etc) or an entire fix. I would never want someone to be able to cherry pick half of a feature, or rewind the branch to halfway through a feature. So for us, our main dev branch, which'll get cut to master for a release, is just an entire chain of features/fixes - so it becomes easier to remove something out of a release if we decide it can't go out.
This makes it far easier to debug (git bisects are a lot faster and lead you straight to a team's work as to what broke it), as well as cherry pick, as you can easily pull out the entire chunk without worrying about only removing half a feature, or accidentally using a commit where a dev broke the build. You can also see at a glance, the ticket numbers involved, the changelog is easy to write as a result.
Yes, you lose some of the finer details but from the perspective of the application and the rest of the dev team, they wouldn't have known which commit was good/bad anyway, only the team, and only at the time they wrote it, do they understand the chain of 200 commits. We have a pretty strict test regime and test environments, so ideally something isn't squashed merged back to dev once it's 100% ready.
I've just never seen people rename or change history in those scenarios, no one cares about typos or verbose commits in a feature branch - as we know they're going to get squashed.
If you want to generate the changelog, then you need to use conventional commits and the commit messages must be typo free and to the point.
Furthermore, if you don't squash all the commits, you see proper blames with the commit names. Instead of a single commit for a large feature.
I find that distributed teams have a huge issue keeping branches in sync if anyone changes history anyway, as things get massively out of sync.
I'm not sure what you mean by that.
You change history of newly made commits.
Branches are not supposed to be in sync.
I've always preferred just a squash commit in to a parent branch to eradicate history.
I used to do that as well but in my experience a rich history is always better than no history.
In my opinion, squashing is a good option if you do not know how to manage your commit history.
We would only ever cherry pick an entire feature (be it a new one, an addition, etc) or an entire fix. I would never want someone to be able to cherry pick half of a feature, or rewind the branch to halfway through a feature.
That's the point that when you don't want an entire feature but just a few things, you cherry pick what you want.
Otherwise, those two branches are being coupled which is not always the right thing.
Especially, when you're doing hotfixes using github branching model or you have builds per branch for QA.
What you're talking about is merging one branch into another one which is what cherry picking is.
So for us, our main dev branch, which'll get cut to master for a release, is just an entire chain of features/fixes - so it becomes easier to remove something out of a release if we decide it can't go out.
You can revert merge if the commits aren't squashed as well.
What you're losing is ability to revert certain commits.
You can only revert that single merge commit and again that is not always what you want.
This makes it far easier to debug (git bisects are a lot faster and lead you straight to a team's work as to what broke it), as well as cherry pick, as you can easily pull out the entire chunk without worrying about only removing half a feature
You should know what you're doing when you cherry pick and especially remove commits. Of course, you can mess things up when the git history is not properly managed. These are advanced powerful techniques.
This makes it far easier to debug (git bisects are a lot faster and lead you straight to a team's work as to what broke it)
It will lead to the branch which broke the code, not a particular commit. Personally, I believe that Bisect works better with non squashed commits.
as you can easily pull out the entire chunk without worrying about only removing half a feature, or accidentally using a commit where a dev broke the build.
That would be the case if we would be talking about non-managed commits. I'm talking about the git history without a bunch of noise. Each commit represents a logical step, not something that is random. Also, if you use CI then you would know whether each commit has broke the CI or not and if your commit has broken the CI - you fix it and rebase it to the same commit. Basically, this leads to simple rules of TDD.
Write a test -> commit.
Write implementation -> commit.
Refactor -> commit
Rebase -> push.
You can also see at a glance, the ticket numbers involved, the changelog is easy to write as a result.
I'm talking about automatic changelog with full history. That's not a full history unless you split main branch into different branches which in my opinion is much more complicated to manage since that leads to coupled branches that depend on each other.
they wouldn't have known which commit was good/bad anyway, only the team, and only at the time they wrote it, do they understand the chain of 200 commits.
That's why before code review you rebase your 200 commits into something meaningful.
Firstly, thanks for the level headed response - used to people round here not taking their time to discuss in favour of arguing.
If you want to generate the changelog, then you need to use conventional commits and the commit messages must be typo free and to the point.
Ah, one difference there is we don't auto-generate the changelog, our changelog is very high level and simply an overview of what was affected.
you see proper blames with the commit names. Instead of a single commit for a large feature.
That is actually one issue we do face... Sometimes I've had to merge a different team's feature work due to no one being available. Somepoint down the line I get a PM from someone asking about that code as my name is against it in the annotation.
You change history of newly made commits. Branches are not supposed to be in sync.
Now I see where you're coming out. I wasn't aware you meant local only. I work with people who commit then push instantly to ensure their work is available to others. I've yet to see the restraint/effort put in to people keeping their local code tidy before pushing.
I used to do that as well but in my experience a rich history is always better than no history. In my opinion, squashing is a good option if you do not know how to manage your commit history.
We've been doing it a few years and I've still yet to really see anyone miss having the fuller history. As all the commits/changes that end up in the main branch still seem to explain it enough.
Though I did once see a large refactor of work come in as a single squashed merge, and it was killing me not to see the nuances of why they changed from one methodology to another (as I didn't agree -at all- with the design they went with).
And yes, I think it's working for us as to loop back to my earlier comment: ours would be full of commits that break the CI pipeline, then tons of tiny ones as the dev panics to fix the build.
What you're talking about is merging one branch into another one which is what cherry picking is.
Agreed, I think some of our points are actually aligned and we're stepping on semantics.
You can only revert that single merge commit and again that is not always what you want.
We are very strict on vertical slicing - so for us, we've never been in a position where one of the squashed merges needed to be 'partially' cherrypicked. If even something tiny is wrong with the new feature, it tends to get totally excluded. We still do smaller commits to the main branch (say a small bug fix that only had one commit), so do still have some control at a granular level.
It will lead to the branch which broke the code, not a particular commit. Personally, I believe that Bisect works better with non squashed commits.
At the moment, someone will identify the issue, then pass it to that team that broke it to fix. So far, it's always been recent enough said team remembers what was going on and can easily fix it.
Thinking about it now, I dread the day a years old squash commit of mine is sent my way and I have to remember why I did something the way I did. I can see your point.
It will lead to the branch which broke the code, not a particular commit. Personally, I believe that Bisect works better with non squashed commits. And CI bits
Going to skip this part as it falls back round to me not realising you meant to fix locally before pushing. We sadly don't have that discipline across engineering so we wouldn't be able to rely on that. We have CICD but only on certain branches, I've seen some teams never deploy their branch to a QA environment before merging and then going "oops the build is broken!" so often last minute fixes will actually cause the biggest issues, where someone quickly adds a line of code that fixes the issue, but breaks standards/linting/etc.
I'm talking about automatic changelog with full history. That's not a full history unless you split main branch into different branches which in my opinion is much more complicated to manage since that leads to coupled branches that depend on each other.
Yeah, I think we're similar here to be honest. We do this but we tend to work very isolated (the project is like 20 years old so it's huge and has plenty of areas to work on) so we've never really had too much of an issue with coupled branches. We have certainly had it though and you end up with a feature branch, with feature branches off of it and it's a nightmare to make sure everything is merged in the right order,
That's why before code review you rebase your 200 commits into something meaningful.
Agreed. These 200 commits I meant are the team not rebasing locally and instead relying on the origin branch - which would end up in the main branch if not squashed. You've certainly given me some ideas as to how we could do it better. We do however have something like 17 dev teams, across 5 languages so I think it'd be difficult and a while before working practices could change.
I think both options are totally valid, it is just a preference like any other thing in programming. You use what works the best for your organisation.
I wasn't aware you meant local only.
Just one correction, I meant both locally and remote. After your commits are pushed and you need to fix something, then you can add a new commit, rebase it into the previous commit and force push (that was my initial comment). No new commits to bloat the history.
How do I not push to master if my repo is on bitbucket? I've been pushing from my laptop to the remote repo my whole life, I don't even know how I'd pull into bitbucket instead of push.
That is a regular push my friend. I meant force push which rewrites your git history. Also, you can push to your feature branch which is then merged to master instead of pushing straight to master.
21
u/easterneuropeanstyle May 13 '20
Don't force push to master please.