简体   繁体   English

恢复本地和远程删除git分支

[英]Recover git branch deleted both locally and remotely

I was in charge of organizing a repo which had many branches to spare and during the merges I didn't notice that a branch didn't fully merge properly but at the time I deleted it both locally and remotely. 我负责组织一个有许多分支备用的仓库,在合并期间我没有注意到分支没有完全合并,但当时我在本地和远程删除它。 Is there any way possible to recover this branch? 有没有办法恢复这个分支?

There is many way, providing you didn't removed it too long ago. 有很多方法,假如你很久以前没有删除它。

  1. When you delete it, it says "was [short_commit_id]". 当你删除它时,它会显示“是[short_commit_id]”。 If you can find that message, just use the command 如果您可以找到该消息,只需使用该命令即可

     git branch mybranch [short_commit_id] 

    to recreate the branch 重新创建分支

  2. If you can't find that message in your log, you can use git reflog to find out what the commit was. 如果在日志中找不到该消息,可以使用git reflog查找提交内容。 git reflog shows you all the modification that occured to HEAD, which can help you figure out what the last commit of that branch was. git reflog显示了HEAD发生的所有修改,它可以帮助你弄清楚该分支的最后一次提交是什么。

    Once you've figured out, just use the command from 1. to recreate the branch. 一旦你想通了,只需使用1.中的命令重新创建分支。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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