A good[ish] website
Web development blog, loads of UI and JavaScript topics
You know the the sinking feeling when you accidentally wiped out half of the repo with a harmless looking rm -rf
. No worried though, there’s a high change of getting it all back if it’s a Git repo.
Just deletion, and no staging or nothing after that. Checkout should do the trick:
$ git checkout .
File got deleted and then added to the staging area, at this point you noticed that something’s wrong:
# Reset the head first
$ git reset HEAD <file>
# Then checkout
$ git checkout <file>
# Or if it’s a ton of files, then use the dot
$ git reset HEAD .
$ git checkout .
If you went the whole way and committed all the deletions, then rollback with reset
to the last commit. The following will roll back 1 commit:
$ git reset --hard HEAD~1
Or rollback to s specific commit ID:
$ git reset --hard 80789fa6a027b3ee3dec760e5784c61b7e4c9d17
Get the commit ID with git log
.
It’s relatively hard to delete anything permanently in Git.
Also, see this nice thread on the dangers of rm
and how to safeguard yourself from yourself.
Comments would go here, but the commenting system isn’t ready yet, sorry.