Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git reset --hard, how will it affect my commits and branches?

Tags:

git

We had a snafu tonight where code checked into git (which gets auto pushed to our application if pushed to the master branch) that caused our site to go down for a bit. I restored an EC2 snapshot to get the site back up, but now I need to cleanup git and get us back on track.

It looks like I need to find the last successful commit to the master branch, grab the first 8 or so characters of it's sha1 id, and run this:

git reset --hard jfe2ldj2
git push origin master -f

Once I do that, everything on the master branch from commit "jfe2ldj2" an later will be wiped from git and can never be recovered. Am I understanding that correctly?

Also, this will not effect any other branches or commits correct? Meaning, that once I run that command and bring the master branch back to say 6 weeks ago, all of the other branches will remain current. Meaning that if I have a number of release and feature branches and they all have multiple commits since 6 weeks ago, all of those branches and commits will still be there?

like image 313
Kris Anderson Avatar asked Apr 08 '13 08:04

Kris Anderson


1 Answers

Once I do that, everything on the master branch from commit jfe2ldj2 an later will be wiped from git and can never be recovered.

As has already been well covered, if changes were committed they can still be recovered even after reset --hard

Also, this will not effect any other branches or commits correct?

Yes, think of a tree, chopping off one branch leaves the others intact.

like image 121
Zombo Avatar answered Oct 25 '22 21:10

Zombo