The importance of backups; the dangers of "rm -rf"
One can't truly appreciate the importance of backups until it saves you from certain doom. I can now say that I personally have been rescued by my backups.
It all started innocently enough - I wanted to wipe out my build directory and start clean again. However, in this case, my build directory happened to have the same name as my Git repository. My Git repository is located in /Users/joe/devel/sipx/git_main. Meanwhile, my build directory is located in /Users/joe/devel/sipx/build/git_main.
Some of you are already shaking your heads, knowing what comes next. Without double-checking my current directory, I typed:$ rm -rf git_main
All right, now it's time to start a new build. I'll just go into my project root directory...$ cd ~/devel/sipx/git_main
-bash: cd: /Users/joe/devel/sipx/git_main: No such file or directory
My stomach churned.
$ pwd
$ /Users/joe/devel/sipx
I had just trashed my project root!
After about 30 seconds of panic - I don't have permission to push my changes to our official repository, so I had lots and lots of changes that hadn't been submitted - I remembered that just the previous Friday, I had started backing up my Git repository to a WD Passport USB hard drive. This was first thing Monday morning, and I hadn't made any new changes yet.
So, thankfully, I was able to restore my entire Git repository:cp -R /Volumes/WD\ Passport/Projects/sipx/git_main .
My woes didn't end there, unfortunately. For compatibility across my different computers I use, the Passport was formatted as a FAT32 partition. The file permissions were all messed up, and apparently my sync software was too smart for its own good - it had changed the newline markers so now all the files appeared changed.
So, when I tried to rebase my branch against the master branch, I got hundreds of errors about "suspicious patch lines" and it wouldn't continue. My stomach started to churn again, but before giving up and tendering my resignation, I searched Google for this error message.
I found a blog post with a strangely appropriate domain name: www.dont-panic.cc, entitled Git on Windows: “You have some suspicious patch lines”. The solution was to edit .git/hooks/pre-commit and comment out the following lines:if (/\s$/) {
bad_line("trailing whitespace", $_);
}
Although I am running a Mac, the trick still fixed my problem. After that, my rebase was successful and I was back in business.
So, remember: Always make backups, and double-check your working directory before you wipe out its contents!



button below.