How to restore a deleted branch
プラットフォームについて: Data Center のみ - この記事は、Data Center プラットフォームのアトラシアン製品にのみ適用されます。
この KB は Data Center バージョンの製品用に作成されています。Data Center 固有ではない機能の Data Center KB は、製品のサーバー バージョンでも動作する可能性はありますが、テストは行われていません。サーバー*製品のサポートは 2024 年 2 月 15 日に終了しました。サーバー製品を利用している場合は、アトラシアンのサーバー製品のサポート終了のお知らせページにて移行オプションをご確認ください。
*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 theCreate Branch
page then choose the tag underBranch from > Tags
Sample
Set the branch name and clickCreate 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>
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.