DEV Community

Discussion on: git reflog saved my ass.

divyansh profile image

What left me wondering is why the master wasn't protected!?

Anyway, git-revert is super helpful in such incidences, it mutates the branch history though. But it makes sure you don't lose your changes under any incident. If you feel like you lost your changes, you can always go back to the reverted commit, checkout a branch from there and continue.

What i'd suggest in such scenario is,

  1. git branch newBranch: Create a new branch keeping the accedental commit, that'll preserve your development and the code so far.
  2. git reset --hard <commit hash> (on master). That'll leave the master unmutated.

Now switch to newBranch and continue with your business like nothing ever happened!

jsn1nj4 profile image

Wouldn't protecting a branch only affect the remote repo? I don't think she pushed to master.