How to restore a deleted branch

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

プラットフォームについて: Cloud のみ - この記事は、 クラウド プラットフォームのアトラシアン製品にのみ適用されます。

問題

You accidentally deleted a branch in your Git repository.

ソリューション

Make sure to perform all of this locally, and confirm your repo is in the state you desire before pushing to Bitbucket Cloud. It may also be a good idea to clone your current repo, and test these solutions out first.


  1.  If you just deleted the branch, you'll see something like this in your terminal:

    Deleted branch <your-branch> (was <sha>)
  2. To restore the branch, use: 

    git checkout -b <branch> <sha>

If you don't know the 'sha' off the top of your head, you can:

  1. Find the 'sha' for the commit at the tip of your deleted branch using

    git reflog
  2. To restore the branch, use: 

    git checkout -b <branch> <sha>

If your commits are not in your reflog:

  1. You can try recovering a branch by reseting your branch to the sha of the commit found using a command like: 

    git fsck --full --no-reflogs --unreachable --lost-found | grep commit | cut -d\  -f3 | xargs -n 1 git log -n 1 --pretty=oneline > .git/lost-found.txt

     

  2. You can then display each commit using one of these: 

    git log -p <commit>
    git cat-file -p <commit>



説明

This page discusses the steps needed to recover an accidentally deleted branch in a Git repository.

製品Bitbucket
最終更新日: 2018 年 10 月 12 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.