How can I restore commit of an unnamed branch in Git?

I made some changes and then made a commit. Then I realized that I was in an unnamed branch. So I checked another branch (with a name). Now I want to restore the commit that I made to the unnamed branch, or switch back to the unnamed branch so that I can put a name on it.

Am I lost forever?

Is there a way to see a list of all commits for all branches and unnamed branches?

+7
source share
1 answer

You can check git reflog to see what your HEAD previously pointed out. When you find the commit id, you can check it via git checkout <commit-id> . After you enable this commit, you can create a branch to specify it via git checkout -b <branch-name> .

+16
source

All Articles