3 ms·
> 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 gi
by tonymet 6mo ago
> 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)