I have recently started using perforce at my work place as our version control system. Before this I have had experience using SVN on google code and GIT for github. Perforce is an enterprise level version control system which uses the concept of depot and workspaces on each perforce clients. Its very easy to set up and even comes with a GUI interface [Perforce Visual Client ] where you can easily see file histories, diffs and other code check-in details.
To read more about how perforce organizes files and changes you can read the official perforce introduction documentation at: http://www.perforce.com/perforce/doc.current/manuals/intro/01_intro.html#1093183
So here are some useful perforce commands:
1. Setup Perforce Workspace:
On doing p4 client a file will open in your default editor. In that file fill in the following details:
Now save the file and your client will be configured.
To sync your current folder with the depot code fire the following command:
p4 sync ...
If you feel that the sync was not done properly you can run p4 sync … again till it gives the message “there are no more files to sync”
Also if you want to force a file to sync again you can type:
p4 sync -f ...
2. Get to know your perforce clients:
If you have multiple clients configured you can see the brief details of all your clients by typing
p4 clients -u <username>
To delete a client:
p4 client -d <clientname>
3. Edit/Add files for change:
All synced files in a perforce workspace are in readonly mode by default. So if you want to edit any file you should first add an edit status to it in the perforce workspace. This will notify the main depot that the file is opened for editing in your workspace which can be used by other users who are making changes to same file.
p4 edit <file_name/relative_file_path>
Similarly, you can add a newly created file by you to the perforce workspace, which again will notify the depot about the change.
p4 edit <file_name/relative_file_path>
4. Creating changelists:
All changes in perforce are saved as changelists. If you want to submit any of your changes to the main depot then you need to create a changelist number. All files which are opened for edit or are added are by default the part of the “default” changelist. If you have created the changelist you will see a number next to your file which will denote the changelist to which the file is added.
To see all the files opened on your workspace:
p4 opened ... # for all files opened for change in workspace.
//depot/<folderpath_to_sync>/<relative_file_path>#<change_number> - edit default change (ktext) #This file is a part of default changelist
//depot/<folderpath_to_sync>/<relative_file_path>#<file_change_number> - edit change <changelist_number>(ktext) #This file is a part of changelist with changelist number =<changelist_number>
To create a changelist:
p4 change #it will open a file where you need to fill the Description, Reviewer and BUGID for the change, Save the file and you will get the changelist number
To see all the changelists by a specific user/client:
p4 changes -u <username> #lists all changes by that user
p4 changes -c <clientname> #lists all changes by that client
p4 changes -c <clientname> -l #displays the changes by that client with their full description texts
p4 changes -c <clientname> -L #displays the changes by that client with their short description texts truncated to 250 words.
p4 changes -s <fixed|opened|...> -c <clientname> #displays all changes by the client which are
5. Submitting changes:
Once you have made all changes you need to submit it to the depot. The change submission usually follows the following process:
Viewing the change diff w.r.t. depot:
p4 diff ... # will present the diff of your change files with the recent files in the depot
#if you want to see the changes in vimdiff you need to make the p4diff editor to be vimdiff
p4 diff ... # will show the diff in vimdiff
Marking the bug fixed by the change:
p4 fix -s fixed -c <changelist_number> <space separated list of BUGIDs>
Submitting the change:
p4 submit -c <changelist_number> #usually if other people are working on the same file this command will result in an error
Resolve the changes & submit:
p4 resolve ... #This will present you will a prompt to resolve the changes. It will have options to either merge the changes or edit the file manually
p4 submit -c <changelist_number> #Submits your changelist with resolved changes
p4 sync ... #sync your workspace so that it reflects the recent changes in the depot