Skip to main content

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:

  1. git reflog -20 - gives you last 20 positions of your HEAD with a little description
  2. git checkout <the_branch_name> - places your HEAD on the branch
  3. git 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:

  1. 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.
  2. Same goes for the on same branch rebase, its just a new tree revritenrewritten next to the old one.
  3. All the history of rebase and your other on HEAD manipulations is writenwritten in the reflog
  4. You can use @{N} annotations from reflog

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.

You still can do git rebase, play with it ass 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:

  1. git reflog -20 - gives you last 20 positions of your HEAD with a little description
  2. git checkout <the_branch_name> - places your HEAD on the branch
  3. git 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:

  1. 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'r branch, from before the rebase, still exists.
  2. Same goes for the on same branch rebase, its just a new tree revriten next to the old one.
  3. All the history of rebase and your other on HEAD manipulations is writen in the reflog
  4. You can use @{N} annotations from reflog

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.

You still can do git rebase, play with it as 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:

  1. git reflog -20 - gives you last 20 positions of your HEAD with a little description
  2. git checkout <the_branch_name> - places your HEAD on the branch
  3. git 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:

  1. 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 your branch, from before the rebase, still exists.
  2. Same goes for the on same branch rebase, its just a new tree rewritten next to the old one.
  3. All the history of rebase and your other on HEAD manipulations is written in the reflog
  4. You can use @{N} annotations from reflog

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.

Source Link
Lukasz Kruszyna
  • 1.9k
  • 1
  • 13
  • 6

You still can do git rebase, play with it ass 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:

  1. git reflog -20 - gives you last 20 positions of your HEAD with a little description
  2. git checkout <the_branch_name> - places your HEAD on the branch
  3. git 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:

  1. 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'r branch, from before the rebase, still exists.
  2. Same goes for the on same branch rebase, its just a new tree revriten next to the old one.
  3. All the history of rebase and your other on HEAD manipulations is writen in the reflog
  4. You can use @{N} annotations from reflog

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.