Squash commit to master that preserves correspondence with dev
To keep master’s history clean, you can
git merge --squash dev. This allows you to preserve the more granular history in the feature or dev branch while keeping master clean.
- Git command to find what branches were merged into current branch and when
- Silent merge tool for git
- Why is git removing rows that were added on one branch when merging?
- Git diverged branches - revert changes
- Tortoisesvn skips recording mergeinfo
- gitlab merge request should not be solved by the requester
After doing this, you can also return to dev, merge master back in, and continue working, starting the whole process over. If you do that, you get a history that looks like this:
The problem is that it’s not clear from the graph that the tip of master and HEAD~1 on dev actually represent the same state (since master is just a squash of dev’s history).
Is there a better way to do this merge so that:
- The equivalence of the squashed commit and the granular commits is apparent
- The granular commit history is preserved in its own branch, should I ever need to look into that level of detail. (this is already being achieved by the solution I described — I’m clarifying that I don’t want to sacrifice this)
One Solution collect form web for “Squash commit to master that preserves correspondence with dev”
I suspect this is not the answer you want, but I think that a normal merge is the best way of communicating the history in a clear way.
Especially if you have a naming scheme for branches and commit messages that make it easy to see which commits have been made in a feature branch and which were in master. (The merge commit automatically gets the name of the merged branch in it, and putting some form of that name in the commit messages will make it all easily traceable)
merge --squash is a hidden merge. That is the fundamental problem. You’ve hidden it but you still want it to be seen.