Comment by grawprog
7 years ago
My last git mistake was pretty terrifying. I decided to try and go back to an old commit on a project on my local machine after about a days work. Somehow I ended up making the commit I wanted to revert to a new branch, then somehow tagged that branch with the name of the commit making git get angry and decide that branch wasn't valid. Then continuing in my ignorance I reset to that branch and tried to checkout only to watch my source and resource files vanish one by one. Deciding the commandline had caused enough trouble I returned to a qgit window I had open, all the source files were still there and I could at least save them one by one. Better refresh the qgit window. Oh shit now qgit's mad at me too. Well there goes thousands of lines of code and about 3 months worth of work. Eventually,after reading gits cryptic error messages and a few google searches I figured out how to remove a tag from a branch and properly checkout an old commit. I was really happy when all those source files reappeared.
Glad you figured it out! Having that much work on a single branch is a process smell in itself, ideally you would have found a way to get that code into the repo before it became that large (break down the work into smaller chunks, hide behind feature flags if needed, etc.). Beyond what you just described, reviewing that much work is nearly impossible to do correctly.
At the very least, if you are going to have a long lived branch, make granular commits and push to a remote repo frequently. That will give you a distributed backup strategy.
Git is not a backup! Had you had one, you could have had your mind at ease.
Ya I realize this now. I usually keep backups. I don't know why I haven't been on this project. I'm using git properly now with proper backups for the project. Though everything's still on the local machine, it's better than the setup I had. I chose to take it as a warning to sort that shit out.
Pushing to a remote is a backup. Gitlab offers private repositories for free.
Until you force push ;)
2 replies →
Before doing anything with git that you're unsure of and could have dire consequences, just clone the directory beforehand. Then run the git commands to your heart's content.
Do yourself a favor and learn git properly. It pays of hugely in the long run. The book that clicked for me was Git Internals [1]
[1] https://github.com/pluralsight/git-internals-pdf