Is there a way to show the names of all the local branches
To see the current local branches:
git branch
if the local branch was not merged or deleted?
If you have not merged the local to any other branch of if you deleted it and git reflog
is not helpful to you, you can always use the git fsck --lost-found
to print out lists of dangling commits (commits which are not accessible from any other commit/branch).
git fsck --lost-found
--lost-found
Write dangling objects into .git/lost-found/commit/
or .git/lost-found/other/
, depending on type.
If the object is a blob, the contents are written into the file, rather than its object name.
Once you have those commits you can simply print them out using: git show <SHA-1>
and once you see a tree search for the root commit and you can now restore it.
# find out all dangling (loos) objects
git fsck --lost-found
# find out the desired root tree using the git cat-file or git show
# Search for tree objects
git cat-file -t <SHA-1>
# once a tree was found print its content
git cat-file -p <SHA-1>
# OR
# again print it content in different way
git show <SHA-1>
# once you found your lost tree - recover it
git checkout <branch_name> <SHA-1>
Some more advanced options:
git fsck --full --no-reflogs --unreachable --lost-found
# --full = Checkout all object in other locations
(read doc to find all about it)
# --no-reflogs = This option is meant only to search for commits that used
to be in a ref, but now aren’t, but are still in that
corresponding reflog.
# --unreachable= Print out objects that exist but that aren’t reachable from
any of the reference nodes.