How to restore a deleted branch

お困りですか?

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

コミュニティに質問

Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Fisheye および Crucible は除く

要約

This Knowledgebase article describes alternative ways to restore a deleted branch in Bitbucket Data Center.

ソリューション

Solution 1 - Push the branch from a local copy

If a user has a local copy of the repository, that person can just push the deleted branch back to the remote repository.

Solution 2 - Review the Push logs in Bitbucket and recreate the branch from the UI

Push logs record pushes to repositories, as well as branch creation and deletion events. This feature is available starting from Bitbucket version 7.1.

Using Push logs:

  • Open the push logs for the repository
  • Select the deleted branch from the Branch  dropdown
  • Review the push logs to determine the last commit in the branch before it was deleted
    Sample
  • Click the commit hash in the push logs to open the commit on a new page
  • Create a tag for the commit.
    Sample

  • Recreate the branch based from the tag created in the previous step.
    Open the Create Branch page then choose the tag under Branch from > Tags 
    Sample

    Set the branch name and click Create branch 

Solution 3 - Review the git reflog and recreate the branch from a local copy 

Using Git: 

  • First, on your local repository, perform git reflog. This will list down all previous HEADs. Find the latest commit hash for the branch that you have deleted.
  • Once you have the commit hash, perform git reset --hard <commit>. This will revert the HEAD back to the latest commit on the branch
  • Recreate the branch again and checkout to that new branch git checkout -b <branchname>
  • Then push the branch, git push origin <branchname>

(warning) Important note: please take a full backup before performing these steps

Related Link

For instructions on how to detect deleted branches, refer to the How to identify a deleted branch page.

最終更新日 2024 年 6 月 3 日

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

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