{"id":133,"date":"2009-06-20T04:59:12","date_gmt":"2009-06-20T04:59:12","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2009\/06\/20\/cheat-sheet-of-perforce-command-line\/"},"modified":"2025-02-01T22:39:44","modified_gmt":"2025-02-01T22:39:44","slug":"cheat-sheet-of-perforce-command-line","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/cheat-sheet-of-perforce-command-line\/","title":{"rendered":"Perforce Web References &#038; Cheatsheet"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-4061 size-full\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2009\/06\/perforce-command-line-cheat.png\" alt=\"perforce-command-line-cheatsheet\" width=\"600\" height=\"400\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2009\/06\/perforce-command-line-cheat.png 600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2009\/06\/perforce-command-line-cheat-300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<table border=\"0\" width=\"100%\">\n<tbody>\n<tr>\n<td class=\"HEADING\">A way to remember data-mining commands<\/td>\n<\/tr>\n<tr>\n<td class=\"HEADING_BODY\">The following is a set of questions that will be used during the Perforce training to remind students which \u201cdata-mining\u201d commands to use for specific situations. Perforce is a terrific tool, but it\u2019s easy to get lost in the choices between \u201cp4 files\u201d and \u201cp4 changes\u201d and \u201cp4 filelog\u201d and so on. This list can help a great deal.<\/p>\n<table border=\"1\" width=\"100%\">\n<tbody>\n<tr>\n<td bgcolor=\"#666666\">\n<div align=\"center\"><strong><span style=\"color: #ffffff;\">the question starts with\u2026<\/span><\/strong><\/div>\n<\/td>\n<td bgcolor=\"#666666\">\n<div align=\"center\"><strong><span style=\"color: #ffffff;\">the answer starts with\u2026<br \/>\n<\/span><\/strong><\/div>\n<\/td>\n<td bgcolor=\"#666666\">\n<div align=\"center\"><strong><span style=\"color: #ffffff;\">Examples<\/span><\/strong><\/div>\n<\/td>\n<\/tr>\n<tr>\n<td>\u201cWhat are the filenames that\u2026?\u201d<\/td>\n<td>\u201cp4 files\u2026.\u201d<\/td>\n<td>p4 files \/\/depot\/\u2026#have<br \/>\np4 have<br \/>\np4 files \/\/depot\/\u2026<br \/>\n(which is the same as)<br \/>\np4 files \/\/depot\/\u2026#head<br \/>\np4 files \/\/depot\/\u2026@label<br \/>\np4 files \/\/depot\/\u2026@client<br \/>\np4 files \/\/depot\/\u2026@2001\/02\/12<br \/>\np4 files \/\/depot\/\u2026@1541<\/td>\n<\/tr>\n<tr>\n<td>\u201cWhat are the differences between the<br \/>\nworkspace copy of XXX and the depot<br \/>\ncopy of XXX?\u201d<\/td>\n<td>\u201cp4 diff \u2026\u201d<\/td>\n<td>\u2022 p4 diff file.c<br \/>\n\u2022 p4 diff file.c#2<br \/>\n\u2022 p4 diff file.c#head<br \/>\n\u2022 p4 diff \/\/\u2026 or \u201cp4 diff\u201d<br \/>\n\u2022 p4 diff \u2013se<\/td>\n<\/tr>\n<tr>\n<td>\u201cWhat are the differences the depot copy<br \/>\nof ______ and the depot copy of ______?\u201d<\/td>\n<td>\u201cp4 diff2 \u2026.\u201d<\/td>\n<td>\u2022 p4 diff2 file1.c file2.c<br \/>\n\u2022 p4 diff2 file1.c#1 file.c#2<br \/>\n\u2022 p4 diff2 dir1\/\u2026 dir2\/\u2026<br \/>\n\u2022 p4 diff2 dir1\/\u2026@now dir1\/\u2026@2000\/01\/02<\/td>\n<\/tr>\n<tr>\n<td>\u201cTell me everything about changelist #___.\u201d<\/td>\n<td>\u201cp4 describe\u201d<\/td>\n<td>\u2022 p4 describe 1231<\/td>\n<\/tr>\n<tr>\n<td>\u201cWhat\u2019s a list of changelists that\u2026.?\u201d<\/td>\n<td>\u201cp4 changes\u2026.\u201d<\/td>\n<td>\u2022 p4 changes<br \/>\n(which is the same as)<br \/>\np4 changes \/\/\u2026<br \/>\n\u2022 p4 changes file.c<br \/>\n\u2022 p4 changes \u2013i file.c | grep 1255<br \/>\n\u2022 p4 changes \/\/depot\/\u2026@label1,@label2<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td class=\"HEADING\">\u201cCheat Sheet\u201d of Perforce command-line<\/td>\n<\/tr>\n<tr>\n<td class=\"HEADING_BODY\">The following list is a set of helpful commands that anyone can run, but that the person administering the Perforce codelines will<br \/>\nbe using a lot. They\u2019re included here for quick reference.<\/p>\n<table border=\"1\" width=\"100%\">\n<tbody>\n<tr>\n<td align=\"left\" valign=\"top\" bgcolor=\"#999999\">\n<div align=\"center\"><span style=\"color: #ffffff;\"><strong>Function<\/strong><\/span><\/div>\n<\/td>\n<td align=\"left\" valign=\"top\" bgcolor=\"#999999\">\n<div align=\"center\"><span style=\"color: #ffffff;\"><strong>Commands<\/strong><\/span><\/div>\n<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" valign=\"top\">Create a new workspace\u2026<br \/>\n1. That\u2019s modeled after the<br \/>\n\u201c1.0dev\u201d workspace \u2013 same<br \/>\nmappings<br \/>\n2. That\u2019s the Perforce defaults,<\/td>\n<td align=\"left\" valign=\"top\">Set the workspace name using \u201cp4 set\u201d or in the environment. Then run:<br \/>\n1. p4 client \u2013t 1.0dev<br \/>\n2. p4 client<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" valign=\"top\">Retrieve a file as of<br \/>\n1. Now (head revision)<br \/>\n2. April 15, 2000<br \/>\n3. Label \u201cxyz\u201d<br \/>\n4. Changelist 123456<br \/>\n5. the revision that client<br \/>\n\u201cjab.work\u201d has retrieved<br \/>\n6. The revision you had before<br \/>\naccidently bashing your disk<\/td>\n<td align=\"left\" valign=\"top\">Use \u201cp4 sync\u201d as follows:<br \/>\n1. p4 sync file.java<br \/>\np4 sync file.java#head<br \/>\np4 sync file.java@now<br \/>\n2. p4 sync file.java@2000\/04\/15<br \/>\n3. p4 sync file.java@xyz<br \/>\n4. p4 sync file.java@123456<br \/>\n5. p4 sync file.java@jab.work<br \/>\n6. p4 sync \u2013f file.java#have<br \/>\nSee \u201cp4 help revisions\u201d for more examples. Note that anywhere that \u201cfile.java\u201d is used in these<br \/>\nexamples, a full pathname (\u201cc:\\work\\projects\\file.java\u201d) or depot name<br \/>\n(\u201c\/\/depot\/rel_218\/base\/projects\/file.java\u201d) could be used.<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" valign=\"top\">Open a file for:<br \/>\n1. add<br \/>\n2. edit<br \/>\n3. delete<br \/>\nAnd then publish the change to others<br \/>\n.<\/td>\n<td align=\"left\" valign=\"top\">Use \u201cp4\u201d with the appropriate verb:<br \/>\n\u2022 p4 add file.java<br \/>\n\u2022 p4 edit file.java<br \/>\n\u2022 p4 delete file.java<br \/>\nThen \u201cp4 submit\u201d to publish it<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" valign=\"top\">What have I changed in the files I<br \/>\nhave opened for edit?<\/td>\n<td align=\"left\" valign=\"top\">\u2022 p4 diff (for all opened files)<br \/>\n\u2022 p4 diff file1 file2 (for specific files)<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" valign=\"top\">Undo a checkout.<\/td>\n<td align=\"left\" valign=\"top\">If the file hasn\u2019t been submitted yet:<br \/>\n\u2022 Use \u201cp4 revert \u2013a\u201d to find all opened files that have no modifications \u2013 it\u2019ll revert those.<br \/>\n\u2022 Use \u201cp4 revert file.java\u201d to revert an individual file.<br \/>\n\u2022 Use \u201cp4 revert \/\/\u2026\u201d to revert all files.<br \/>\nRemember that \u201cp4 revert\u201d is irreversible.<br \/>\nIf the file has been submitted, you\u2019ll need to open the file for edit and check in a prior revision.<br \/>\nUse very good change descriptions to say what you did and why.<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" valign=\"top\">Interrupt your work to edit a single<br \/>\nfile and check it in, without any other<br \/>\ndisruptions. (You\u2019re hacking Java and<br \/>\nsomeone needs a \u201crelnotes.txt\u201d<br \/>\nupdated ASAP to issue a release.)<\/td>\n<td align=\"left\" valign=\"top\">Two ways:<br \/>\n1. Edit the file and submit only that file.<br \/>\n\u2022 p4 edit relnotes.txt<br \/>\n\u2022 do the modifications<br \/>\n\u2022 p4 submit relnotes.txt<br \/>\n2. Make a new changelist to manage just that change.<br \/>\n\u2022 p4 change<br \/>\nremove all the files in this change from the Files: section, it\u2019ll create an empty<br \/>\nchange.<br \/>\n\u2022 p4 edit \u2013c XXX relnotes.txt<br \/>\nwhere XXX is the change number in the previous step<br \/>\n\u2022 p4 submit \u2013c XXX<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" valign=\"top\">Publish your work to others<\/td>\n<td align=\"left\" valign=\"top\">\u201cp4 submit\u201d<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" valign=\"top\">Compress the data on the net<br \/>\nbecause you have a slow modem line<br \/>\nbetween your workspace and the<br \/>\nserver.<\/td>\n<td align=\"left\" valign=\"top\">Run \u201cp4 client\u201d for your workspace, and change the options from \u201cnocompress\u201d to \u201ccompress\u201d.<br \/>\n(Read \u201cp4 help client\u201d for details.)<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" valign=\"top\">Get the list of\u2026<br \/>\n1. All changelists applied to the<br \/>\nbase codeline<br \/>\n2. \u2026 to the prodxyz codeline<br \/>\n3. \u2026 to the prodxyz codeline,<br \/>\nincluding those applied<br \/>\noriginally to another codeline<br \/>\nand integrated into prodxyz<br \/>\n4. All revisions of file.java<\/td>\n<td align=\"left\" valign=\"top\">Use \u201cp4 changes\u201d or \u201cp4 filelog\u201d as follows:<br \/>\n1. p4 changes \/\/depot\/eng\/\u2026<br \/>\n2. p4 changes \/\/depot\/eng\/prodxyz\/\u2026<br \/>\n3. p4 changes \u2013i \/\/depot\/eng\/prodxyz\/\u2026<br \/>\n4. p4 filelog file.java<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" valign=\"top\">Push \u2026 from the base codeline<br \/>\n(\u201cprodxyz\u201d) to the 1.0.1 codeline<br \/>\n(\u201cprodxyz-1.0.1\u201d):<br \/>\n1. Push change #1232<br \/>\n2. From change #129 to #134<br \/>\n3. all changes in the base<br \/>\ncodeline<\/td>\n<td align=\"left\" valign=\"top\">Use \u201cp4 integrate \u2013b prodxyz-1.0.1\u201d as the place to start, in each case:<br \/>\n1. p4 integ \u2013b prodxyz-1.0.1 \/\/\u2026@=1232<br \/>\n2. p4 integ \u2013b prodxyz-1.0.1 \/\/\u2026@129,@134<br \/>\n3. p4 integ \u2013b prodxyz-1.0.1 (no additional args)<br \/>\nNote that this assumes that the named branch specification \u201cprodxyz-1.0.1\u201d has been created<br \/>\nby your project lead or administrator using \u201cp4 branch\u201d.<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" valign=\"top\">Push \u2026 from the prodxyz-1.0.1<br \/>\ncodeline to the base (\u201cprodxyz\u201d)<br \/>\ncodeline:<br \/>\n1. Push change #1235<br \/>\n2. From change #127 to #128<br \/>\n3. all changes in the base<\/td>\n<td align=\"left\" valign=\"top\">Use \u201cp4 integrate \u2013b prodxyz-1.0.1\u201d as the place to start, in each case:<br \/>\n1. p4 integ \u2013b prodxyz-1.0.1 \u2013r @=1235<br \/>\n2. p4 integ \u2013b prodxyz-1.0.1 \u2013r \/\/\u2026@127,@128<br \/>\n3. p4 integ \u2013b prodxyz-1.0.1 \u2013r (no additional args)<br \/>\nThe \u201c-r\u201d reverses the order of source\/target in that named branch specification.<br \/>\nNote that for the \u2018selective integration\u2019 cases, you\u2019ll want to be VERY CAUTIOUS of \u2018accept<br \/>\ntheirs\u2019.<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" valign=\"top\">Show the \u2018diff\u2019 between the<br \/>\nprodxyz-1.0.1 codeline and its<br \/>\nparent<\/td>\n<td align=\"left\" valign=\"top\">\u201cp4 diff2 \u2013b prodxyz-1.0.1\u201d (This works because \u201cprodxyz\u201d is the name of the branch<br \/>\nspecification, not because \u201cprodxyz\u201d is part of \u201c\/\/depot\/prodxyz\/\u2026\u201d)<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" valign=\"top\">What branches do I have?<\/td>\n<td align=\"left\" valign=\"top\">If you use \u201cp4 branch\u201d to create branch specifications and use them consistently, then \u201cp4<br \/>\nbranches\u201d provides this info.<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" valign=\"top\">How do I make a new codeline<br \/>\nnamed prodxyz-2.0?<\/td>\n<td align=\"left\" valign=\"top\">There are several steps:<br \/>\n1. Make a named branch specification. Save it.<br \/>\n\u2022 \u201cp4 prodxyz-2.0\u201d<br \/>\n\u2022 if you want to exactly imitate another branch (e.g. prodxyz), use<br \/>\n\u201cp4 branch \u2013o prodxyz-1.0.1 &gt; tmp\u201d to capture the output, edit this temporary file<br \/>\nand replace the \u201c1.0.1\u201d references with \u201c2.0\u201d, then run \u201cp4 branch \u2013i &lt; tmp\u201d.<br \/>\n2. Run the \u201cp4 integrate\u201d command to populate this new codeline. Submit the change.<br \/>\n\u2022 p4 integrate \u2013b prodxyz-2.0<br \/>\nor, if you want to push content as of a certain label (e.g. \u201cxyz\u201d) from the parent,<br \/>\np4 integrate \u2013b prodxyz-2.0 \/\/\u2026@xyz<br \/>\n\u2022 p4 submit<br \/>\n3. Send e-mail telling everyone about this codeline and what it\u2019s used for.<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" valign=\"top\">Put everything onto a laptop, you\u2019re<br \/>\ngoing to the beach and want to hack.<br \/>\n(This assumes that you won\u2019t be<br \/>\nconnected to a net while away.)<\/td>\n<td align=\"left\" valign=\"top\">There are several steps:<br \/>\n1. Connect the laptop to the net.<br \/>\n2. Run \u201cp4 sync\u201d to populate the source onto the laptop.<br \/>\n3. Leave for the beach.<br \/>\n4. While editing, use \u201cchmod\u201d or \u201cattrib\u201d to make the files writeable. Make your changes.<br \/>\n5. Get back to work, reconnect to the net.<br \/>\n6. Run the following commands to tell you what\u2019s updated and open them for<br \/>\nadd\/edit\/delete:<br \/>\n\u2022 p4 diff \u2013se | p4 \u2013x \u2013 edit<br \/>\n\u2022 p4 diff \u2013sd | p4 \u2013x \u2013 delete<br \/>\n\u2022 find . \u2013type f \u2013print | p4 \u2013x \u2013 add<br \/>\nThen inspect what\u2019s opened (\u201cp4 opened\u201d) and what you\u2019ve changed (\u201cp4 diff\u201d). Submit or<br \/>\nrevert as appropriate.<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" valign=\"top\">Run a checkpoint<\/td>\n<td align=\"left\" valign=\"top\">\u201cp4 admin checkpoint\u201d \u2013 only an administrator can run this. (An administrator has \u201csuper\u201d<br \/>\npermissions in the \u201cp4 protect\u201d data.)<br \/>\nBe sure to back up the checkpoint, the current journal, and each of the \u201cdepot\u201d directories on<br \/>\nthe server machine!<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" valign=\"top\">Change the security\/permissions<\/td>\n<td align=\"left\" valign=\"top\">\u201cp4 protect\u201d \u2013 only an administrator can run this.<br \/>\nAlso\u2026<br \/>\n\u201cp4 protects\u201d \u2013 used in 2006.1 and later to TELL you your permissions .<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" valign=\"top\">Make a label<\/td>\n<td align=\"left\" valign=\"top\">It\u2019s a two-step process:<br \/>\n1. Make the label using \u201cp4 label xxx\u201d<br \/>\n2. Populate it using \u201cp4 labelsync \u2013l xxx\u201d<br \/>\nor if you have a specific list of files,<br \/>\n\u201cp4 labelsync \u2013l xxx file1 file2 \u2026\u201d.<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" valign=\"top\">Copy a label\u2019s contents to another<br \/>\nlabel. Assume that the existing label<br \/>\nis \u201cxxx\u201d and the new label is to be<br \/>\n\u201cabc\u201d.<\/td>\n<td align=\"left\" valign=\"top\">Again, a two-step process:<br \/>\n1. Make the label using \u201cp4 label \u2013t xxx abc\u201d<br \/>\n2. Populate it using<br \/>\n\u201cp4 labelsync \u2013l abc \/\/\u2026@xxx\u201d<br \/>\nNote that the second step is really identical to the second step in the previous question \u2013 we\u2019re<br \/>\njust specifying a very specific list of revisions [of files] to include in the new label.<br \/>\n(Also\u2026<br \/>\nIn 2005.1 and later, \u201cp4 tag\u201d will make the label and apply it to a set of files.)<\/td>\n<\/tr>\n<tr>\n<td align=\"left\" valign=\"top\"><\/td>\n<td align=\"left\" valign=\"top\"><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>A way to remember data-mining commands The following is a set of questions that will be used during the Perforce training to remind students which \u201cdata-mining\u201d commands to use for specific situations. Perforce is a terrific tool, but it\u2019s easy to get lost in the choices between \u201cp4 files\u201d and \u201cp4 changes\u201d and \u201cp4 filelog\u201d&#8230;<\/p>\n","protected":false},"author":1,"featured_media":4061,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[370],"tags":[3203,824,3206,384,3210,3211,3209,2837,373,3207,3204,3205,3213,3217,3216,3214,3215,3212,3208],"class_list":["post-133","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-perforce","tag-cheat-sheet","tag-command-line","tag-data-mining-commands","tag-p4","tag-p4-changes","tag-p4-filelog","tag-p4-files","tag-p4v","tag-perforce","tag-perforce-command-reference","tag-perforce-command-line","tag-perforce-command-line-cheat-sheet","tag-perforce-command-line-guide","tag-perforce-command-line-help","tag-perforce-command-line-list","tag-perforce-command-line-reference","tag-perforce-command-line-resource","tag-perforce-command-line-tutorial","tag-reference-guide"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/133","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=133"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/133\/revisions"}],"predecessor-version":[{"id":7254,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/133\/revisions\/7254"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/4061"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}