How to recover a deleted arm in Git

1

I deleted a git arm via git branch -D <nomedobraco> and I need the commits I had made 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 get it to the location. Can you recover an arm in this situation?

    
asked by anonymous 12.05.2017 / 19:52

1 answer

2

Yes, there is a way to get it back, because the arm reference has been deleted, but the commits does not. Just find the SHA1 of an arm commit and perform checkout on it. Being in this commit , simply create an arm from it, and then you will have a new arm, but with the same commits as the deleted arm. Let's go step by step:

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

git reflog

Found the commit, grab the SHA1 and run the command below to commit.

git checkout <sha1>

Now, just create an arm from where we are.

git checkout -b <nomedobraco>

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

git checkout -b <nomedobraco> <sha1>
    
12.05.2017 / 19:52