But it I believe there should be a simpler and more elegant way.
There is a way which does not involve patches: reset --hard
followed by reset --soft
.
First, mark the current HEAD of your branch: we will need to move that HEAD without modifying Alpha
, so let's create a new temporary branch called 'tmp
' where Alpha
is.
git checkout Alpha
git checkout -b tmp
Then we go back to an Beta HEAD commit with the right content.
git reset --hard Beta
That resets the index (and working tree) to the right content, but that also moves HEAD. However, that moves tmp
HEAD, not Alpha
HEAD.
move back tmp
HEAD to where mAlphaaster
is, but without modifying the index or the working tree (which are representing what we need for a new commit)
git reset --soft Alpha
make a new commit, on top of Alpha
/tmp
HEAD, which represents the right content (Beta HEAD commit content).
git commit -m "new commit, image of an old one"
Finally, force Alpha
to be where tmp
is: one new commit later.
git branch -M tmp Alpha
git checkout Alpha
git branch -d tmp
Now a regular git push
is enough, any collaborator can simply pull as usual, and still get the old reset content.
git push