Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> My first troubling discovery was in 2025, when I made several errors then did a push -f to GitHub and blew away the git history for a half decade old repo

git reflog is your "backup". it contains every commit and the resulting log (DAG) going back 90 days. If you do blow away a remote commit, don't fret, it's in your reflog

  # list all of the remote HEAD commits you've ever worked with 
  git reflog origin/master

  # double check it's the right one
  git log -5 origin/master@{2}

  # reset the remote to the right one
  git push -f origin $(git rev-parse origin/master@{2}):master

  # (optional) reset your local branch
  git reset origin/master@{2}

  # at this point your local branch has time-traveled, but your working dir will be in the present state (e.g. all the relevant files will show as changed)


Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: