Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to discard all uncommitted changes in Perforce?

Tags:

perforce

What is the p4 command to throw away all my uncommitted change in my Perforce workarea?

When using Git, the analogous command is: git reset --hard

like image 712
Victor Lyuboslavsky Avatar asked Apr 01 '14 15:04

Victor Lyuboslavsky


2 Answers

If you haven't checked out the files you've edited, first do

p4 reconcile ...

to get the changes tracked by Perforce.

You don't need this if the changes you want to undo are already in any changelist.

Then, from the root of your workspace,

p4 revert ...

(... is the Perforce wildcard for everything under a given directory, not something you have to fill in yourself).

If you also want to delete untracked files from the disk, then if you're using the 2013.2 release or later, you can pass -w to p4 revert to also delete newly added files. See this answer for some background on this option.

The reconcile step would first detect these files and mark them for add, and then the revert step would unmark them for add and delete them. If -w isn't available then there's no clean way to do this and the files will be left untracked and on the disk after the revert.

like image 165
GS - Apologise to Monica Avatar answered Oct 06 '22 20:10

GS - Apologise to Monica


p4 revert is the command you're looking for.

Remember, if you want to revert a specified changelist just, you must specify its changelist number like:

p4 revert -c changelistnumber

Or, if you are not running it from the workspace root, specify the workspace/client name, like:

p4 revert //myWorkspace/...

like image 33
Bruno Brs Avatar answered Oct 06 '22 18:10

Bruno Brs