Hacker News new | ask | show | jobs
by Yasuraka 610 days ago
Did you mean reflog?

Either way, even simpler, imho, than any log that one has to comb through after the fact is to create a named backup

  branch=$(git branch --show-current) && git switch -c backup-${branch} && git switch -
Carry on as planned and if you bork it all, switch to the backup branch which retains the original commits and all, delete the borked one and have another go

  git switch backup-somebranch && git branch -D somebranch && git branch -m somebranch
3 comments

You don’t have to comb through the reflog for the pre-rebase branch state. Use `@{1}` from the reflog of the branch (not `HEAD`).[1]

Note: First I thought that `ORIG_HEAD` was the thing. But that won’t work if you did `git reset` during the rebase.

(`ORIG_HEAD` is probably “original head”, not “origin head” (like the remote) that I first thought…)

[1] You just have to comb through documentation!

I do this as well but `git reset --hard backup-somebranch` and try again if I mess it up.
I have a custom bash function named "backup_branch" that does exactly that, along with "restore_backup" and "delete_backups". It's made my life 10x simpler.