Git reset -hard, how will this affect my commits and branches?

Today we had snafu, where the code was checked on git (which is automatically translated into our application if it is clicked on the main branch), which led to the fact that our site has slightly decreased. I restored the EC2 snapshot to get the site back, but now I need to clear git and get us back on track.

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

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

As soon as I do this, everything on the main branch from the jfe2ldj2 commit will later be erased from git and cannot be restored. Do I understand this correctly?

In addition, it will not affect any other branches or fix the correctness? The point is that as soon as I run this command and return the master branch to say 6 weeks ago, all other branches will remain current. This means that if I have several releases and function branches, and all of them have several commits from 6 weeks ago, will all those branches and commits be there anyway?

+4
source share
1 answer

As soon as I do this, everything on the main branch from commit jfe2ldj2 will later be erased from git and cannot be restored.

As has already been well covered , if changes have been made, they can still be restored even after reset --hard

In addition, it will not affect any other branches or fix the correctness?

Yes, think of a tree, chopping off one branch, leaving the rest intact.

+5
source

All Articles