Squash commit to master that preserves correspondence with dev

In a common git workflow, you branch off master into a feature branch or a dev branch, make many small commits, and then merge back into master when your work is tested.

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.

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:

enter image description here

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:

  1. The equivalence of the squashed commit and the granular commits is apparent
  2. 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)

  • “cannot pull into a repository with state: merging_resolved”
  • How to induce a `<<<<<`/`>>>>>` merging state in Git?
  • Django merge two migrations with the same ID?
  • How to force a merge to succeed when there are conflicts?
  • How to check if a commit has been merged to my current branch - somewhere in time?
  • Strategy For Keeping Git Feature Branches Up to Date
  • Git merge internals
  • git: How to redo a merge conflict resolution (before committing the merge)?
  • 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)

    The merge --squash is a hidden merge. That is the fundamental problem. You’ve hidden it but you still want it to be seen.

    Git Baby is a git and github fan, let's start git clone.