Muokkaa

Jaa


Restore a deleted Git branch from the web portal

Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019

This article addresses how to restore a deleted Git branch using the web portal in Azure Repos. If you need to restore a Git branch in your own repo from Visual Studio or the command line, push your branch from your local repo to Azure Repos to restore it.

Prerequisites

Category Requirements
Project access Member of a project.
Permissions - View code in private projects: At least Basic access.
- Clone or contribute to code in private projects: Member of the Contributors security group or corresponding permissions in the project.
- Set branch or repository permissions: Manage permissions permissions for the branch or repository.
- Change default branch: Edit policies permissions for the repository.
- Import a repository: Member of the Project Administrators security group or Git project-level Create repository permission set to Allow. For more information, see Set Git repository permissions.
Services Repos enabled.
Tools Optional. Use az repos commands: Azure DevOps CLI.

Note

In public projects, users with Stakeholder access have full access to Azure Repos, including viewing, cloning, and contributing to code.

Category Requirements
Project access Member of a project.
Permissions - View code: At least Basic access.
- Clone or contribute to code: Member of the Contributors security group or corresponding permissions in the project.
Services Repos enabled.

Note

There's no retention policy on deleted branches. You can restore a deleted Git branch at any time, regardless of when it was deleted.

Restore branch

  1. Open your repo on the web and select the Branches view.

  2. Search for the exact branch name using the Search all branches box in the upper right.

  3. Select the link to Search for exact match in deleted branches. If there's a deleted branch that matches your search, you can find which commit it pointed to when upon deletion, who deleted it, and when.

    Search for exact match in deleted branches in the Azure DevOps Services/TFS web portal

  4. To restore the branch, select the ... icon next to the branch name and then select Restore branch from the menu. The branch gets recreated at the last commit to which it pointed. Branch policies and permissions do not get restored.

    Restore your deleted branch in the Azure DevOps Services/TFS web portal

If you reused the same branch name for different commits, you might not see all the commits you're expecting when you restore the deleted branch. In that case, go to the Pushes page of the restored branch to see the entire history of the branch.

View all pushes for your restored branch

You can go to a specific commit, then select New branch from the ... icon. From there, you can use a pull request, cherry-pick, or merge to get the commits back into the desired branch.

New branch from commit