p4 revert

Synopsis

Discard changes made to open files.

Syntax

p4 [g-opts] revert [-a -n -k -w] [-c change] [-C client] [--remote=remote] file ...

Description

Use p4 revert to discard changes made to open files, reverting them to the revisions last synced from the depot (with p4 sync). This command also removes the reverted files from the pending changelists with which they’re associated. An administrator can use the -C option to revert another user’s open files.

  • When you revert files you opened with p4 delete, the files are reinstated in the client workspace.
  • When you revert files that have been opened by p4 add, Perforce leaves the client workspace files intact.
  • When you revert files you’ve opened with p4 integrate, Perforce removes the files from the client workspace.
  • When you revert files you’ve opened with p4 move, only the file open for move/add can be reverted.

The host name is implied and the username is not needed.

Options

-a

Revert only those files that haven’t changed (in terms of content or filetype) since they were opened.

The only files reverted are those whose client revisions are the following:

  • Open for edit but have unchanged content and unchanged filetype.
  • Open for integrate via p4 integrate and have not yet been resolved with p4 resolve.
  • Open for add, but are missing from the workspace.

    Files that are open for add that are missing but which also have pending integrations will not be reverted.

-c change

Reverts only those files in the specified changelist.

Revert all files in a specific change in a client workspace

$ p4 revert -c 345627 "//..."

-C client

Revert another user’s open files. This option implies the -k, -H, and -u options. -H and -u are global options.

Revert a single file in a client workspace:

$ p4 revert -C bruno_ws //depot/www/dev/Jam.html

Revert all files in a client workspace:

$ p4 revert -C bruno_ws //...

This option is useful in freeing up exclusive locks held on an edge server. In such a case, the command needs to be directed to the edge server where the client resides. For example:

$ p4 revert -C SusanClient //depot/src/x.cc

The option is also very useful in cleaning up after old users' workspaces: you need to revert any open files in a workspace before you delete it.

-k

Keep workspace files; the file(s) are removed from any changelists and Perforce records that the files as being no longer open, but the file(s) are unchanged in the client workspace.

-n

List the files that would be reverted without actually performing the revert.

This lets you make sure the revert does what you think it does before actually reverting the files.

--remote=remote

Reverts the file in your personal server, and additionally — if the file is of type +l — releases the global exclusive lock on the file in the shared server from which you cloned the file.

For more information, see the section Support for exclusive locking in the Fetching and Pushing chapter of Using Helix for Distributed Versioning.

For more information, see the section "Support for exclusive locking in personal servers" in the "Fetching and Pushing" chapter of Using Helix for Distributed Versioning.

-w

Files that are open for add are to be deleted (wiped) from the workspace when reverted.

g-opts

See “Global Options”.

Usage Notes

Can File Arguments Use Revision Specifier? Can File Arguments Use Revision Range? Minimal Access Level Required

No

No

list

  • p4 revert differs from most Perforce commands in that it usually requires a file argument. The files that are reverted are those that lie in the intersection of the command line file arguments and the client view.

    You don’t need to specify a file argument when using the -a option.

  • Reverting a file that has been opened for edit will overwrite any changes you have made to the file since the file was opened. It may be prudent to use p4 revert -n to preview the results before running p4 revert.

Examples

p4 revert //...

Revert every file you have open, in every one of your pending changelists, to its pre-opened state.

p4 revert -c default //...

Revert every file open in the default changelist to its pre-opened state.

p4 revert -n *.txt

Preview a reversion of all open .txt files in the current directory, but don’t actually perform the revert.

p4 revert -c 31 *.txt

Revert all .txt files in the current directory that were open in changelist 31.

p4 revert -a

Revert all unchanged files. This command is often used before submitting a changelist.

Related Commands

To open a file for add

p4 add

To open a file for deletion

p4 delete

To copy all open files to the depot

p4 submit

To read files from the depot into the client workspace

p4 sync

To list all opened files

p4 opened

To forcibly bring the client workspace in sync with the files that Perforce thinks you have, overwriting any unopened, writable files in the process.

p4 sync -f