All Products
Search
Document Center

Object Storage Service:revert-versioning

Last Updated:Mar 20, 2026

Run revert-versioning to revert a deleted object in a versioning-enabled bucket back to its most recent previous version.

How it works

When you delete an object in a versioning-enabled bucket, OSS inserts a delete marker and keeps all previous versions intact. The revert-versioning command removes that delete marker, which makes the most recent previous version the current version again.

Note: revert-versioning only works on objects that have a delete marker as their current version. If an object was overwritten rather than deleted, the command has no effect on it.

Prerequisites

Before you begin, ensure that you have:

  • A versioning-enabled OSS bucket

  • The oss:ListObjectVersions and oss:DeleteObjectVersion permissions on the target bucket. For details, see Attach a custom policy to a RAM user

  • ossutil installed. For ossutil 1.6.16 and later, use ossutil directly as the binary name. For earlier versions, update the binary name based on your operating system. For details, see ossutil command reference

Syntax

ossutil revert-versioning oss://bucketname[/prefix]
[--encoding-type <value>]
[-r, --recursive]
[--start-time <value>]
[--end-time <value>]
[--include <value>]
[--exclude <value>]
[--payer <value>]

Parameters and options

Parameter/OptionDescription
bucketnameThe name of the bucket that contains the objects to revert.
prefixA prefix to filter objects and directories by name.
--encoding-typeThe encoding of the prefix that follows oss://bucketname. Valid value: url. If not specified, the prefix is not encoded.
-r, --recursiveReverts all objects whose names match the specified prefix. Without this option, only the specified object is reverted.
--start-timeA UNIX timestamp. Objects deleted before this time are not reverted.
--end-timeA UNIX timestamp. Objects deleted after this time are not reverted.
--includeReverts only objects that match the specified pattern. For details, see Options --include and --exclude.
--excludeSkips objects that match the specified pattern. For details, see Options --include and --exclude.
--payerThe fee payer for the operation. Set to requester to charge the requester for traffic and request fees.

Examples

Revert a single object

ossutil revert-versioning oss://examplebucket/exampleobject.jpg

Revert all objects with a prefix

ossutil revert-versioning oss://examplebucket/destdir -r

Revert all deleted objects in a bucket

ossutil revert-versioning oss://examplebucket -r

Revert objects deleted within a time range

The following command reverts objects deleted between 16:22:58 and 16:39:38 on June 16, 2020 (UTC+8):

ossutil revert-versioning oss://examplebucket -r --start-time 1592295778 --end-time 1592296778

Revert objects by file type

Revert only TXT objects:

ossutil revert-versioning oss://examplebucket --include "*.txt" -r

Revert all objects except JPG objects:

ossutil revert-versioning oss://examplebucket --exclude "*.jpg" -r

Sample output

A successful run returns the number of reverted objects and the elapsed time:

revert versioning object count is 10, batch list count is 10

0.066413(s) elapsed

Access a bucket in a different region or account

To access a bucket in a different region, add -e to specify the bucket's endpoint. To access a bucket owned by a different Alibaba Cloud account, add -i and -k to specify that account's AccessKey ID and AccessKey secret.

The following command reverts exampletest.png in testbucket, which is in the China (Shanghai) region and owned by a different account:

ossutil revert-versioning oss://testbucket/exampletest.png -e oss-cn-shanghai.aliyuncs.com -i yourAccessKeyID -k yourAccessKeySecret

What's next

  • Overview — Learn how versioning works in OSS.

  • Delete marker — Understand how delete markers affect object retrieval.