I want to overwrite all the content in a development branch with another one (namely, master), but I don't want to miss the older commits on the dev branch.
This is what I want:
I tried both to merge with ours strategy and by doing an hard reset but the dev branch keeps losing the older commits.
What I'm trying to obtain is a commit that has zero diff between blue and red, and the dropped code while diffing blue with the first black one.
Just to share an overview of the solutions tried until now. By doing this:
git checkout master
git merge -s ours dev
git checkout dev
git merge master
I obtain this (dev gets all the history from master)
By doing this
git checkout dev
git reset --hard master
I obtain this (if I push develop i will lose all the black commits):
If i do this:
git checkout dev
git merge $(git commit-tree -p dev -m "Align master > dev" master^{tree})
I obtain this (almost perfect, yet I would be difficult to recall the exact moment when I did the trick):