According to the p4 help revert, I get:
The -w flag causes files that are open for add to be deleted from the
workspace when they are reverted.
But, when I try to use the -w, I get the following:
> p4 revert -w ./dir1/newfile.c
//depot/test/dir1/newfile.c#1 - was add, reverted
> ls ./dir1/newfile.c
./dir1/newfile.c
Am I missing something, or is this a bug in p4? (Note: my version is as follows):
Proxy version: P4P/LINUX26X86_64/2014.2/1099171 (2015/06/16)
"p4 revert" only undoes the operations that haven't been submitted yet.
It will not delete the file from disk. You should delete the file separately after reverting.
Related
Is there a way to check all the files which are opened in the p4 client and can be reverted if we know that they are not edited.
In P4V, on the pending changelist in question, right-click and choose Revert Unchanged Files.
On the command-line, you can achieve the same with p4 revert -c CHANGELIST -a (you can even add -n to preview the operation). See p4 help revert for more information.
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
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.
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/...
My workflow for testing my changes to our source code on a remote machine is the following:
1) On local machine: Shelve changes that I'd like to test
2) On remote machine (ssh):
$ p4 revert //...
$ p4 sync
$ p4 unshelve -s <changelist number>
$ ./run_test_scripts
This seems to work fine when I've only made changes to files that already exists. If I've added new files these will be created during p4 unshelve, but not deleted during p4 revert. The documentation says that this is what p4 revert does so it isn't unexpected, but causes some problems if I want to test the same files again:
$ p4 revert //...
<some file>#none - was add, abandoned
$ p4 sync
File(s) up-to-date.
$ p4 unshelve -s <changelist number>
Can't clobber writable file <some file>
Is there way I can delete the files abandoned Perforce?
I think what you're looking for is p4 revert -w. From the help:
The -w flag causes files that are open for add to be deleted from the workspace when they are reverted.
Note: I'm using the 2013.2/719516 client against a 2013.2/708877 server, in case that switch was added recently...
Edit: just reread your question - this is a workaround, perhaps not a full solution...
There is a setting in P4Win that allows you to overwrite files when unshelving:
Overwrite workspace files even if they are writeable
I normally use that in combination with another option (again in the gui):
Revert checked our files before unshelving
They solve my problem.
Looking in the console output while running this from the gui, it looks like it is the -f parameter in the unshelve command.
p4 unshelve -s <changelist> -f -c <changelist> <files>
In Perforce P4V I have a file in a pending changelist. I want to revert the contents of the file but keep the file in the changelist. How can I do that?
I tried Perforce's revert command but that removes the file from the changelist.
The only way to accomplish this (short of copy/pasting the original contents back into this file, but that seems silly) is to revert and reopen it. Shelving, by itself, does not revert the file. The concept of "shelve and revert" is still two operations.
This is not readily possible, as other respondents noted.
If you are okay with a multi-step solution, you could
Right-click the file in the changelist and choose "diff against have revision".
In the diff window, under "Edit" choose "Edit right/left pane" (whichever side yours is
on).
Copy the contents of the original and paste them over your edited workspace version
Save the file.
Your file now has no changes, and it is checked out in the same changelist.
Using the command line, it can be done in three stages. If you are using windows I highly recommend having a unix environment, e.g. cygwin (which is the one I used.)
Assume your changelist number is XYZ and you have shelved the files in their current revision (just for the sake of it!)
Step 1: get a list of files and put them in a temp file.
p4 describe XYZ | grep \/\/ | sed -e 's/\.\.\. //'| sed 's/#.*//' > temp
Step 2: revert all the files in the changelist
p4 revert -c XYZ //...
Step 3: check out / edit the files again
cat temp | xargs p4 edit -c XYZ
I assumed all the files are in edit mode (i.e. not an already opened file or a deleted file).
PS : delete temp, if you are fussy :)
I don't believe this can be done, even from the command line, since p4 sync (even with -f) explicitly excludes operations on open files.
The feature you're looking for is shelving. This will revert the file, but keep a shelved version in the changelist, which you (or someone else on a different client) can unshelve later.
I'm new to Perforce and, to be honest, I'm hating it.
I had about 20 files in my c:\workspaces\perforce directory and I selected all of them and hit the delete key.
They were all checked in before I deleted them.
I've been pulling my hair out trying to figure out how to get them back (Perforce is sooooo unintuitive) but there's nothing that stands out to a n00b like me to.
How can I get the latest revisions back into the directory from Perforce?
You need to do a force sync.
On the command line:
$> p4 sync -f
In the P4V GUI:
Right-click on the directory to update
Select 'Get Revision'
In the dialog, check 'Force operation'
Click 'Get Revision'
The perforce server keeps track of which files you pulled in last time. This is done so that, the next sync only brings in the files which have changes since the last sync, instead of all the files once again.
To override this behavior, you need to use the -f option.
The -f flag forces resynchronization even if the client already has
the file, and overwriting any writable files. This flag doesn't
affect open files.
If you're using the command line client, you can run this command from the directory where you want to sync up:
p4 sync -f ...
You might also want to check the list of opened files, since sync -f will not be bringing in changes corresponding to those files (even if you have deleted them).
This command should list all the opened files:
p4 opened ...
If you have any files listed in the above list, which you had deleted as well, you should revert them before running sync -f.
p4 revert <FILE1> <FILE2>
p4 sync -f ...
If you're using p4v, you could follow the steps mentioned by dwinkle:
1. Right click the folder in your workspace
2. Choose `Get Revision` in the context menu.
3. Choose `Get Latest revision`
4. Check `Force Operation (replace file even if you already have the revision specified)
5. Click on `Get Revision` button to fetch the files.
To look at the list of opened files using p4v, you would have to look at your list of pending changelists. You should be looking in the default changelist, if you have not put the files in any speficic changelist. Right click on files that you see there that you had deleted earlier, and choose Revert.
if you have files checked out, and then deleted. You need to revert(p4 revert -a //...) the folder before you get latest forced (p4 sync -f).
An alternative:
p4 reconcile
p4 revert //...
If you don't care about the old client, one solution would be to pull down a new client:
p4 newclient
p4 sync
If you want the client to have the same name, you can do a forced sync as others have mentioned:
p4 sync -f
If you want the client to have the same name, but your directory is no longer recognized as a p4 workspace, you will need to delete the client and then recreate it.
p4 -c <client_name> client -d <client_name>
p4 newclient
Right click on parent directory.
Click "Reconcile" in context menu.
Let a new change list be created.
Right click changelist.
Revert change.
In my case I tried everything and I couldn't get all of my files to revert, so I tried deleting them and then I couldn't get all of them back. I restarted my pc, and tried numerous solutions found online. In the end my problem was solved by one or all of the following: upgrading to the latest P4V application, running the application with elevated permissions, and going to lunch after forcing get latest.
If you wasted half of a day. You may want to try the above.
I've deleted all the files in my directory. How can I get them back?
One wrinkle to this that I just stumbled over is that if you remove the directory you can't just use p4 sync -f to get it back. I wanted a complete clean version of the directory so I did a:
rm -rf directory1
However when I did a p4 sync -f directory1 on it, it spits out:
directory1 - no such file(s).
What I found that works is to recover a file inside of the directory first:
p4 sync -f directory1/some-file
You will have to know the name of one of the files inside of the missing directory which you can get using:
p4 files //depot/some/path/directory1/\*
Once you get one of the filenames, do:
p4 sync -f directory1/some-file
This should create the directory1 directory. Then you can do a full sync inside of the created directory:
cd directory1
p4 sync -f ...
Hope this helps someone else.