sync cleanly to another perforce label - ubuntu-14.04

TL;DR: How do I sync an existing p4 workspace to a new label, so that all my previous changes are undone, and it is as good as a new sync?
Hi,
I have a perforce workspace synced to a label L1.
I added/deleted/edited a few files
I moved a few files inside a folder (mv a.txt b.txt new_folder/)
I want to cleanly sync this workspace to label L2 now.
I already removed all shelved and pending changelists, then tried
p4 reconcile -w ... && p4 revert -w ... && p4 sync ...#L2
Looks like it almost works, except that the files I moved inside a new folder do not get synced (p4 sync -f works though). But I do not want to use p4 sync -f on the entire workspace, as it would resync the unchanged files as well.
I am sorry if this question has been answered before, I am pretty new to perforce, so maybe could not find the correct terms to search for.

The ... path limits the scope of each operation to the current directory; if you ran those commands from a different directory than the one you moved the files to, that may be why they didn't get synced. I'd do:
p4 revert //...
p4 clean //...
p4 sync #L2

Related

Sync ONLY the differences in the depot but recieving error "- must refer to client"

I want to be able to sync ONLY the differences in the depot into my workspace.
I do not want to re-sync all the source files which already match.
I currently can see the difference with this command:
p4 diff -sd //depot/source/...
But when trying to use this command to sync the depot differences to my local workspace:
p4 diff -sd //depot/source/... | p4 -x - sync -f | p4 //depot/source/...
I receive this message in the terminal:
"- must refer to client"
Note: Prior to performing all of the above command I set my client using
p4 set P4CLIENT=MYWORKSPACE
To sync only the files that have been updated on the server since you last synced, do:
p4 sync
The default behavior of the p4 sync command is to sync only changed files; you don't need to perform any special gyrations to make that happen.
The server's notion of what's different between the server and your workspace is dependent on its records of what it sent you the last time you synced. If you've messed around with your workspace in unsupported ways (i.e. you've modified files that Perforce made read-only without "opening" them for modification), those records have been invalidated. You can fix this one of two ways, depending on what you want to do with your modifications:
p4 reconcile
will open the files you modified, allowing you to choose between reverting the modifications or submitting them.
p4 clean
will simply overwrite your modifications, similar to a p4 sync -f, but p4 clean will do a diff to figure out which files you modified and will only re-sync those files.

Deleted (not submitted) directory in Perforce: cannot revert, force-sync, reconcile or do anything else

I have deleted a directory in a 3rd-party Perforce client. It should have used p4 delete, but I cannot be sure. It was not submitted.
Now:
I don't see the deleted directory in p4v.
p4 revert fails:
p4 revert //depot/path/deleted-directory/...
//depot/path/deleted-directory/... - file(s) not opened on this client.
I cannot force-sync deleted-directory to revert the deletion:
p4 sync -f //depot/path/deleted-directory
//depot/path/deleted-directory no such file(s).
p4 sync -f //depot/path/deleted-directory/...
//depot/path/deleted-directory/file1.txt#2 - deleted as /Users/me/depot/path/deleted-directory/file1.txt
I cannot reconcile them:
p4 reconcile //depot/path/deleted-directory/...
//depot/path/deleted-directory/... - no file(s) to reconcile.
p4 opened doesn't see them:
p4 opened
File(s) not opened on this client.
How do I get this deleted directory into a changelist or at least revert it?
I tried all suggestions from "I've deleted all the files in my directory. How can I get them back?" except for checking out a new workspace, which I will eventually do.
Short answer:
p4 undo //depot/path/deleted-directory/...#head
p4 submit
That will undo the head revisions in that directory (i.e. the deletion) by creating new revisions that are copied from the prior ones.
Longer answer to explain why all the things you tried didn't work:
p4 opened and p4 revert both operate on files that are currently open. If you hadn't yet submitted, then revert would put the files back, but since this deletion was already submitted, there were no open files to revert.
When you force-synced you were just forcing a re-sync to the head revision, which is deleted (just like the files in your workspace), so no matter how hard you force the sync all you're going to get is a lot of nothing. If you had done:
p4 sync "//depot/path/deleted-directory/...#<head"
in order to sync to the revision prior to #head, that would have done the trick. Note that no -f flag is necessary. Once the files were synced to the correct revision, you would also be able to undo the delete by following that sync command with:
p4 add //depot/path/deleted-directory/...
p4 submit
Similarly, reconcile didn't do anything because the files are deleted at the head revision and deleted in your workspace, so there's nothing to reconcile. If you wanted to get really weird with it you could undo the delete via reconcile by using a combination of sync and flush to simulate the condition of having re-added new copies of the files:
p4 sync "//depot/path/deleted-directory/...#<head"
p4 flush //depot/path/deleted-directory/...
p4 reconcile //depot/path/deleted-directory/...
In addition to being unnecessarily complex, this reconcile-based solution will lose the information of which revision the re-added files came from (thanks to the p4 flush), so I would not recommend it. Go with undo and if you're on an old server version that doesn't support that do the normal sync/add thing.

How to do I get files I deleted locally but didn't commit the changes?

I have deleted some files/folders in my local machine but I did not commit the changes to repository.
How to get the deleted files back?
I am not getting the deleted files after performing the p4 sync -f. Why I am not getting the deleted files after the force sync?
If you haven't reverted the changes Perforce will still think you want to delete those files so won't restore them.
You need to go to the pending changelist and do a "revert" on those files to get them back.
Use the "p4 revert" command:
p4 revert -c default //...
This "revert[s] every file open in the default changelist to its pre-opened state."
Source
If you don't want to revert all the files, move the files you want to revert to a separate changelist and use the "-c" option.
If you only have a few files to revert you can specify the name of the file:
p4 revert lib/libopenssl.a include/openssl.h
for example, reverts exactly those two files (thanks to Bryan).

How to discard all uncommitted changes in 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
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/...

I've deleted all the files in my directory. How can I get them back?

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.

Resources