🎶If I could turn back time🎶

David Kirsch
3 min readSep 8, 2020

Turns out Cher wasn’t the only person who wishes they could turn back time. As a software developer, we often use github to store our programs. Github is a great tool to learn if you are truly interested in entering this field. However, the other day I found myself in a bit of a predicament. I pushed up an API key in my program.

For anyone unfamiliar with API keys, programmers use them to request data from external servers. You can think of an API key as a social security number, so it is best to hide it from the public.

When companies find out that you leaked your key to their API, often times you are fined, and I’m not talking about a few dollars….I’m talking thousand$. So When I realized I had just pushed up my code along with my API key, you can imagine the horror that had struck my face.

It’s one thing to delete a commit on your local repo before pushing it up to the hub, however once you push it up, you will find it very difficult to remove that commit. Yes, you can edit/delete the key in your program, make a new commit and push that up, but the history on your remote repo will still be there for all to see.

But wait! There is a solution!!

With some deep, deep, deep digging on the internet I was able to figure out a solution that saved me from paying $$$ in fines.

If you made the mistake like me and pushed some delicate information up to your repo, or you just want to remove some commits you made in the past, follow my instructions below and you will be where you were before you made that commit.

I will preface this by saying when you remove previous commits from your repo, you will lose everything you did beyond that point of the commit. So, only remove these commits if it is absolutely necessary.

Step 1:

On your remote repo, click on the counter-clockwise arrow with the word commits.

You will be taken to a list of your history within this repo and you can select on the commit you want to revert to.

From here, you will see a long string of characters next to the word commit. This is how you will identify what commit you want to revert back to.

Step 2:

Now while you are in your repo on your terminal, you will type in the following commands

//git reset --hard 'your commit id'
git reset --hard 18acda5fd165546f4099ae898a89bde303f18a8f

That will reset the HEAD of your repo to that version in history.

//this will force push the newly reset HEAD up to the remote repo. //Use + and then whatever branch you want to rewrite. In the example //below, I am using the master branch as the one I am updating.
git push origin +master

That’s it! You can breathe again. With these simple steps you will save yourself the headache of trying to figure out how to rewrite history.

Source:

https://git-scm.com/docs/git-push#:~:text=configured%20with%20remote.-,*.,push%20to%20the%20master%20branch)

--

--

David Kirsch

Full Stack Software Engineer. Bachelor’s in Technology —Specializing in Software Development from NYCCT — CUNY. Flatiron School Graduate