Hacker News new | ask | show | jobs
by johnea 610 days ago
With syslog, everything in git is "fearless"
4 comments

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
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.
Assuming this is the reflog, this is not true. Because the working copy doesn't get snapshotted, it is relatively easy to lose uncommitted data. I've spent much of my professional career working on source control and even I've lost uncommitted data a few times.

Dropbox doesn't have a notion of uncommitted data. Why should source control?

I have to use reflog, rebase -i and frequent commits to cover the spectrum of edge cases I deal with weekly. No two of them accomplish the entire job.
You should try out Jujutsu :)
It's on my list.
As long as you commit everything, yes. The reflog is the safety rope of git. Everyone who isn't confident with the reflog should go and learn it right now.

Pick your most important repo. Make sure everything is committed. Doing something stupid like `git reset --hard HEAD~100`. Look how fucked your work is. Do `git reset --hard HEAD@{1}`. Look at how nothing was lost.

> reflog should go and learn it

Among its other virtues, reflog makes safe the highly empowering 'git-commit --amend'.

Yep, and even the more powerful fixup workflow where you can essentially amend commits other than HEAD. I do it via git-autofixup: https://github.com/torbiak/git-autofixup
Long rebases are not. That's the whole point.