I'm fairly new to git and only work by myself so I don't use many of the features it can do but I am running into a process that either I am thinking about it wrong or doing something wrong.
I have a master branch with 1 commit (init).
I have a develop branch with 180 commits.
Today I am finally ready to merge the develop branch into the master, I did some reading and found out about squash. This seems like something useful since I wouldn't pollute the master branch with the same WIP commits that are in the develop branch.
So I ran
git checkout master
git merge --squash develop
git commit
From here everything looks as I expected, master
has 2 commits, develop
still has 180. In my head I now check out develop
again and continue working. I pushed to bitbucket
and took a look around at my project to see this merge and noticed the following:
1 commit(s) on master and not on develop
179 commit(s) on develop and not on master
Is this just expected behaviour and I am supposed to ignore it or did I do something wrong.
When you select the Squash and merge option on a pull request on GitHub.com, the pull request's commits are squashed into a single commit. Instead of seeing all of a contributor's individual commits from a topic branch, the commits are combined into one commit and merged into the default branch.
You can choose to squash merge when completing a pull request in Azure Repos. Choose Squash commit under Merge type in the Complete pull request dialog to squash merge the topic branch.
You should consider using squash if your team prefers a linear project history. This means that the history held by your main branch should not contain merges. A squash merge makes it possible to keep changes condensed to a single commit, supporting this strategy nicely.
This is expected since git merges all your commits into a single commit, which will be a different one compared to the ones in your develop branch. Think of the commits as a container of a set of changes, if you change the contents you'll have a different one.
You'll either have to accept this scenario, or you could adapt your workflow by working in feature-branches, e.g. master - develop - feature-branch.
Once a feature is done you make a squash-merge from feature-branch to develop and delete the feature-branch. Now you can make merges from develop to master without all the WIP commits, e.g. when you make new releases or such.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With