How do I download files from perforce to a location other than a workspace? - perforce

I want to get files from Perforce without putting them into a workspace.
E.g.
I have made changes in 2 files.
file1.cs
file2.cs
Now I want to build the project using updated file1.cs, so I want to get latest files except for file1.cs.
I thought I will get another local copy of project and build it.

I'm not sure what you really want to do, but you can get the contents of a file from the depot without using a workspace definition by using "p4 print". Example:
>p4 print -o fileName.cs //depot/path/to/fileName.cs

As far as I am aware you cannot sync files from a Perforce depot without using a workspace since this is the way it tracks what version of files you have in your workspace and also where to put them on your local machine (as well as a few other things).
I'm not sure I entirely understand your problem but if what you need to do is get another copy of the file1.cs you have in the depot without removing the changes you have to it you can simply copy the changes to another location or shelve them and re-sync the file. The more complete and less dangerous solution is to create another workspace pointing to a different physical location on your machine but the same depot location.
This explains how to create a workspace if you need it:
http://www.perforce.com/perforce/doc.062/manuals/boilerplates/quickstart.html
Make sure the 'Root' path is different to that of your current workspace, you can check what your current workspaces root is by going to the workspace tab in P4V and viewing it.
Once you have created the new workspace create a new connection and select it then sync the file(s) you need.

So I want to get latest files except file1.cs
You shouldn't do that; you should update all files and resolve any conflicts with file1.cs
Consider the situation where someone else has made changes to file56.cs that relies on changes also made to file1.cs. If you take their changelist but overwrite (or do not take) their file1.cs, then your build will break.

Shelve file1.cs so you can safely revert your local change:
p4 shelve file1.cs
p4 revert file1.cs
Now you can do your build with whatever version of file1.cs you want (you can sync back to an older version or whatever).
When you're ready to return to your change:
p4 unshelve -s CHANGE

If you're in the UI you can use File->Export To... which will copy the selected file to any folder you want.

I found the workaround but not the solution.
I get another local copy of project then build the project and submit the change.

I found an easy way of doing this with git:
$ git p4 clone //depot/your/folder

Related

Make the contents of a perforce directory exactly match the latest depot version

I would like to make the contents of a directory in a Perforce workspace be exactly the same as the latest depot contents. I want this to work no matter what has gone on in the workspace. (For example, editing files without opening them in perforce, creating unsubmitted changesets, etc.)
So far I have come up with running this series of commands, in order:
p4 clean ...
p4 revert ...
p4 sync ...
Will this do what I want? Is this the correct order? Is there a simpler way?
Those are the correct commands, and you do need all three:
revert is needed to discard changes to files you've opened
clean is needed to discard changes to files you haven't opened (including added files)
sync is needed to make sure you're at the very latest depot revision
You should either put clean after the revert or add -w to revert; otherwise files that were opened for add will be skipped by the clean (because they're open) and then revert will "abandon" them in the workspace (the -w option causes revert to delete/"wipe" added files instead of abandoning them). Other than that, I think the order is unimportant.

Perforce Change List too Big

In Perforce, I have created a change list that has over 200,000 files (by doing a rename on a directory). This change list is now too big to submit or revert. When I try, I get an error saying that the operation took too long.
I am now stuck with this change list that has my original directory in marked for delete state and a new directory that hasn't been submitted. Is there a way undo this change list?
You can revert the files a few at a time. As a test, you could run p4 revert //path/to/some/file and verify that it's able to revert that file.
Once you know that's working, you just need a way to automate the process.
You could script something up that starts in the root directory and runs through all directories breadth-first, running p4 revert //path/to/folder/* at each folder (I think you could also use client paths).
You can revert via the command line using the p4 tool. I do not think you can revert the files from the UI. The associated documentation shows various examples of how revert all or specific files (see the Examples section):
http://www.perforce.com/perforce/r12.1/manuals/cmdref/revert.html

Is there a way to use tortoise svn to backup my modified files?

I have a bunch of files that I've changed that I don't really want to commit, but I would like to back them up locally in case I would like to use them again. (Then I'll revert them.)
TortoiseSvn working status helps to view the modified files, but I want a way to save them all to a separate directory like Backups\, preferably with their folder heirararchy still in tact.
How can I do that?
UPDATE:
Apparently branching is the way to go.
But what I did was just copied the modified files paths to the clipboard (which is an option in tortoisesvn) then to a file, and created a program to copy them to a backup folder.
You can create a branch and commit those files only in that branch.
You can commit it inside a branch, so it doesn't affect your current 'trunk' or branch.
If you had a try with bazaar , that is compatible with SVN, there is a shelf command to temporarily store a set of modification and apply back them later.

Perforce Revert Shows "file(s) not opened on this client"

I'm trying to open an existing Perforce application. I made some local changes, like deleting files, which I want to undo (that is, I want my local copy to exactly match the repository once more -- delete added files, restore deleted files, and undo changes).
When I try to revert using the p4v gui client, I see this error:
file(s) not opened on this client
What am I doing wrong?
I did manage to revert all the changed files, but not the added/removed files.
Edit: I did the following:
Connect to a Perforce server using p4v
Map a directory to my local file system (lets say C:\Perforce)
Get the latest version of the repository
Go to C:\Perforce in Windows Explorer
Delete some files and folders
Add some files and folders
I would like to get back to the "pristine" state, the copy of exactly what's on the server when I got the latest version of the repository for the first time.
By the looks of the edited description you added and deleted files directly on the filesystem and not through perforce. Therefore Perforce doesn't know anything about those changes so there is nothing to revert. Typically when you want to add a file you use 'p4 add" (or the equivalent p4v operation), and when you delete, you should use 'p4 delete' (or again, the equivalent p4v operation).
Really, the best option to get back to a pristine state is to nuke the local copy of the code in c:\perforce (in windows explorer), go to p4v, right click the area you want to sync, and choose "Get Revision..." and in the subsequent dialog, make sure that the "force operation" checkbox is checked. This will tell Perforce that you want a new copy of everything regardless of whether you had it synced or not.
You can also run "reconcile offline work" in p4v. Right click the depot area and choose that option. It will scan through the local folder structure and give you a report of what files have been added that don't exist in perforce, what files were deleted, and what files were modified. From that dialog, you can right click on local files that don't exist in perforce and delete them, or you can 'p4 add' them. You can also sync deleted files.
HTH.
Just an extra not to point out another cause for this.
If the file name contains an unusual character that cannot be translated correctly the name on the client will never match that on the server.
The solution in this case is to spot that character in the file name (it will be a question mark emblem on Linux) and use a wildcard to help identify the file to the server so it can delete it etc (p4 deleting the file is a way to go).
This answer may not be your case. This happened to me when I edited the files on my local disk without logging into p4.
A quick fix at commandline is:
p4 login # make sure you've logged in
p4 edit <filename> # let p4 know you've edited the file
p4 revert <filename> # revert to "pristine" state
You can use p4 reconcile -w to restore your client to the state of the server. There is an alias called clean, which is also available in P4V on the right-click context menu as Clean....
There are several additional flags to control whether added and deleted files are deleted or restored, respectively.
The -w flag forces the workspace files to be updated to match the
depot rather than opening them so that the depot can be updated to
match the workspace. The -a, -d, and -e flags when used with -w
update workspace files as follows:
-a Files with no corresponding depot file are deleted.
-d Depot files not in the workspace are added.
-e Modified files are restored to the last version synced.

In perforce, how do I remove pending changes for NEW/ADDED files not submitted?

I am trying to remove a pending changelist in perforce. All the files (20 old) are new but have not be committed/submitted yet. So in p4Win, they show a RED + cross. I am failing to remove these files from the change list. How do I go about getting rid of these files?
Thanks for the answers to right-click and revert. I have tried that but it fails with the example error strings below.
Operation: user-revert
Librarian digest source/.../foo.c failed.
RCS checkout 1.715484 failed!
RCS no such revision 1.715484!
//source/.../foo.c#1 - was add, reverted
I've also tried the p4 revert command but it fails with same error(s).
Fixed with "revert -k" by perforce support group. They suspect it may be due to overlay values in the client workspace but have not been very specific.
How are you trying to remove the files?
It's been a while since I used Perforce in anger but I seem to remember that you just had to right click and revert the file.
I've just tried this and it worked OK for me (the programmer's lament!). It uses the following p4 command:
p4 revert //depot/test.txt
Where test.txt is the name of the test file.
Update
Does the new file still exist locally on your hard drive?
Does the path where the file would be in the depot still exist? ie. what's in the "..." of your path.
Revert files, right-click on file in change list and select revert, this will remove added files.
Maybe try Perforce support at this stage.
To remove all added files in current and sub directories:
p4 revert ...
In my case this happened because the RCS files (the actual files with ,v extension in the depot that contain all the revision information) were literally missing the information for the revision in question. I was able to restore the files from backup.
I had the same problem, I had added the .exe files but wanted to exclude them afterwards. The perforce documentation helped:
http://www.perforce.com/perforce/doc.current/manuals/p4eclipse/topics/adding.html
Excluding Files from Source Control
Important: you cannot exclude files after you have placed them under
Perforce control. If you have files opened in a changelist and you
want to exclude them from Perforce control, revert them from the
changelist before excluding them.
Worked like a charm.

Resources