You still can do git rebase, play with it assas you want, than recover all the changes from before.
Assuming you have done your rebase of some branch into the master
, and you don't like it:
git reflog -20
- gives you last 20 positions of your HEAD with a little descriptiongit checkout <the_branch_name>
- places your HEAD on the branchgit reset --hard <old_sha1_found_in_reflog>
- places your HEAD and branch on the old ref, this way you can recover old branch.
There are some mechanics to understand here:
- You NEVER delete anything in git, not with commands, anyway. Its the garbage collector that comes through and deletes unreferenced branches (default 3 months). So you'ryour branch, from before the rebase, still exists.
- Same goes for the on same branch rebase, its just a new tree revritenrewritten next to the old one.
- All the history of
rebase
and your other on HEAD manipulations is writenwritten in thereflog
- You can use
@{N}
annotations fromreflog
So, nothing is lost after the rebase
, you just have to know how to find and recover it.
For example you can place yourself a tag before the rebase
than revert to it or delete it. it evades you all the SHA1 research step.