hfutils.repository.rollback

This module provides functionality to rollback a Hugging Face Hub repository to a specific commit.

It includes a function to clone a repository, reset it to a specified commit, and force push the changes back to the remote repository.

hf_hub_rollback

hfutils.repository.rollback.hf_hub_rollback(repo_id: str, rollback_to: str, repo_type: Literal['dataset', 'model', 'space'] = 'dataset', revision: str = 'main', endpoint: str | None = None, hf_token: str | None = None, silent: bool = False)[source]

Rollback a Hugging Face Hub repository to a specific commit.

This function clones the repository, resets it to the specified commit, and force pushes the changes back to the remote.

Parameters:
  • repo_id (str) – The ID of the repository to rollback.

  • rollback_to (str) – The commit hash or reference to rollback to.

  • repo_type (RepoTypeTyping) – The type of the repository (‘dataset’, ‘model’, or ‘space’). Defaults to ‘dataset’.

  • revision (str) – The branch or tag to clone. Defaults to ‘main’.

  • endpoint (Optional[str]) – The Hugging Face Hub endpoint. If None, uses the default endpoint.

  • hf_token (Optional[str]) – The Hugging Face authentication token. If None, attempts to use stored credentials.

  • silent (bool) – If True, suppresses command output. Defaults to False.

Raises:

subprocess.CalledProcessError – If any Git command fails during the process.

Usage:
>>> hf_hub_rollback('username/repo', 'abc123', repo_type='model')

Note

This function performs the following steps:

  1. Checks for Git installation (without LFS requirement).

  2. Creates a temporary directory for the operation.

  3. Clones the specified repository into the temporary directory.

  4. Resets the repository to the specified commit using ‘git reset –hard’.

  5. Force pushes the changes back to the remote repository.

Warning

This operation can overwrite remote history and can not be cancelled. Use with caution.