简体   繁体   中英

Git - Undo Overwriting a Branch

Instead of

git checkout <mybranchname>

I did

git checkout -B <mybranchname>

which has overridden the branch I wanted to switch to with the branch I was switching from.

Is there a way to undo this?

Type git reflog . There you should see a checkout of your renamed branch. Something like:

56d04f9 HEAD@{8}: checkout: commit-message of your missing branch

The first column is the hash of the commit. So you copy the hash and type git checkout <hash> . In the example it would be git checkout 56d04f9 . This should checkout your missing branch and you can rename it back.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM