How to send 500 lines of Python code up in flames

Jupyter Lab was open. The notebooks and data I was working on were sitting on the left.

It was close to home time.

After digging through docs all day to figure out how to get some old code running, my brain was looking like this: FQRUQ#$%(#$QJTQITHqRjlrjkaw

Every time I push to GitHub I have to look up a guide.

3-minutes later, I sent off a push command and noticed all the files were being pushed. Not what we wanted. Only the new stuff was to go up.

CRTL-C.

CRTL-C.

CRTL-C.

It stopped.

> git reset
> git add [notebooks]
> git commit -m "adding latest datascience notebooks"
> git push origin master

"You're already one commit ahead of master."

What?

Google time.

*clicks on first stackoverflow link*

No good.

*clicks back*

*next link*

Better.

"To rollback a commit you can use git revert..."

Back to the shell.

> git log

*copies previous commit hash key*

> git revert [insert above hash key]

All of a sudden two files disappeared from the Jupyter Lab directory. The exact two files I wanted to commit.

And the data folder was now empty. "Huh?"

30-minutes of trying to revert a revert later, 1 of the 2 notebooks were nowhere to be seen. We saved one because I still had it open. The other wasn’t as lucky. ~500 lines of Python code gone.

Moral of the story?

When it comes to Git. Move slow and save things.

-

PS. I found a really cool (and colourful) guide on how to use git. I’ve bookmarked for future reference. If you want to step up your git/GitHub game, you might be interested.

Source: https://www.linkedin.com/feed/update/urn:l...