How to recover a deleted arm in Git

Asked

Viewed 3,871 times

1

I deleted an arm from git via git branch -D <nomedobraco> And I need the commits I did on that arm, I need to restore it. The problem is that it had not been sent to the remote, so there is no way to pull it to the site. There is a way to recover an arm in this situation?

1 answer

4


Yes, there’s a way to get it back, because the arm reference was deleted, but the commits no. Just discover the SHA1 of an arm commit and perform checkout to him. Being in that commit, just create an arm from it and then you will have a new arm but with the same commits of the deleted arm. Let’s step-by-step:

This command below will list the commits performed in the project so you can identify the last commit of the deleted arm.

git reflog

Found the commit, get the SHA1 from it and execute the command below to go to the commit.

git checkout <sha1>

Now, just create an arm from where we are.

git checkout -b <nomedobraco>

Okay, we have our arm. This could all be summed up to a single commit if you already know the SHA1 of commit:

git checkout -b <nomedobraco> <sha1>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.