Just wondering if there's a way to recover them after they've been deleted. I'm assuming here that I've deleted it both locally and remotely.
Asked
Active
Viewed 173 times
3 Answers
3
You can use git reflog
to find the SHA1 of the last commit of the branch. From that point, you can recreate a branch using
git branch branchName <sha1>
source: Git undo local branch delete

Community
- 1
- 1

Lajos Veres
- 13,595
- 7
- 43
- 56
-
also unreferenced commits/branch will get permanently deleted after a repack. – Loïc Faure-Lacroix Mar 07 '14 at 16:53
-
If you can answer a question by linking to another question, you should probably vote to close it as a duplicate. – Keith Thompson Mar 07 '14 at 16:54
1
branch is a lightweight pointer to a commit in Git. So you can always create a branch pointing the exact commit again using the command again.
git branch branchname <sha1-of-commit>

rogue-one
- 11,259
- 7
- 53
- 75
0
As others have explained, you can use the SHA-1 value. It is a good idea to tag the branch before deleting that way it is removed from the branch list but you keep information about the branch and can use the tag to recover it. Also you can enter a message explaining that it was removed and the reason.

M0eB
- 151
- 2
- 3