By: Saurav

2019-03-14 19:20:00 UTC

As OhShitGit pointed out, Programming (Including git) is...lets say.. interesting! I have fcuked up a few times myself. I do learn from mistakes I make but it sucks to be in that phase. So here are my Oh Shit moments:

1. Git : Forced Push to the wrong branch

#I wanted to remove a commit which had a spelling mistake, so I did

git:newBranch~/projects/$ git reset <hashKey>
git:newBranch~/projects$ git log

#here is when I messed up:
git:newBranch~/projects$ git push origin master -f 

#It forced pushed to the master and the last PR merge got removed (oops!)

#The right thing would have been 
git:newBranch~/projects$  git push -f  OR git push origin newBranch -f 

How did I solve it?

I went to github, took the PR branch which was deleted, restored the branch so that it had all the commits. There was a new PR created on GitHub (The last PR was already approved). Then I merged it with master.

A good thing was that only the last commit to master (which was a merge branch) was removed. Otherwise I would have to go through each deleted branch and iterate the process.

Lesson Learned: Don't do Copy Paste from your notes no matter how tired you are

2. Rails: Using delete instead of destroy

While testing a new feature on a production application, I created two test assets in production. I tested the feature and it worked great. Now was the time to remove it from production. It was already 7:45 in the evening and I was almost ready to go back home.

Well! then I hit


If you don't know, delete only deletes the said resource from the database but doesn't run the callbacks. Destroy, on the other hand, allows cleanup methods and other actions to be run. Thus if you are using elastic search for indexing, destroy is the way to go. Below is a snapshot of documentations.

Read carefully

1 hjlch2zm0sr4ascemqtwnw

1 xrwkm5colqlaqvvadv0lfg

The search page threw an error because the elastic search was including that video while rails couldn't find it. So for a few minutes, I fcuked up the production application used by a lot of people. Thankfully, my mentor was kind enough to get back on a slack call with me and we figured a way out for the document to be removed from the elastic search index. The way was to use do_update

Lesson learned: Just to be safe, always use destroy instead of delete when you are working on a production console.

3. Running rspec with .env variable

RAILS_ENV=test foreman run bundle exec rspec spec

Owned & Maintained by Saurav Prakash

If you like what you see, you can help me cover server costs or buy me a cup of coffee though donation :)