I need to revert a whole branch with a single commit like this:
[topic]
o---o---o-------X
/
| [master]
---o---o---o
The commit X
must have state like a master~2
(the origin point of topic branch)
My solution is:
git rev-list --reverse master..topic | while read SHA; do
git revert -n ${SHA}
done
git commit -m "Reverted topic branch"
Is there a better (shorter) solution?
A PURPOSE OF THIS
Imagine I have a kind of almost-git-flow based repo.
[release-3]
o---o---o---o
/ \ [fix-for-rc-3]
/ o---o---o
/
| [development]
---o---o---o
I have a development
branch, upcoming release-3
branch and a so-called hot-fix-feature-for-rc-3
branch. In this branch I'm doing some ugly hack to get my release done but I don't want it in a development
at all because more "correct" solution is already landed here but can't be applied to a release-3
branch by some reason. So, I must do the following...
[release-3]
o---o---o---o--------------------M
/ \ [fix-for-rc-3] /
/ o---o---o----------------X
/ \
| \[development]
---o---o---o---------------------------------D
I must merge fix-for-rc-3
to a release-3
(point M), then do a "revert-all-this-shit" commit (point X) and merge it do development
(point D) so this code will never get here, even then a whole release-3
branch is merged to development
then release is done.
That's why I need to revert a whole branch...
THE PROBLEM
While the root issue is solved, there are still problem getting fork point of a branch cause' if topic
is already merged to release
merge-base
will fail.