{"id":4543,"date":"2018-01-08T12:00:29","date_gmt":"2018-01-08T12:00:29","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=4543"},"modified":"2021-02-27T09:09:54","modified_gmt":"2021-02-27T09:09:54","slug":"syncing-missing-modified-files-to-a-specific-version-in-perforce","status":"publish","type":"post","link":"https:\/\/www.scmgalaxy.com\/tutorials\/syncing-missing-modified-files-to-a-specific-version-in-perforce\/","title":{"rendered":"Syncing missing\/modified files to a specific version in Perforce"},"content":{"rendered":"<p>I think this is the 5th time I&#8217;ve had to figure this out in the past few years, so this time I&#8217;m going to preserve it here for posterity\u00a0<img decoding=\"async\" src=\"http:\/\/www.andrewgrant.org\/wordpress\/wp-includes\/images\/smilies\/icon_smile.gif\" alt=\":)\" \/><\/p>\n<p>The problem is usually one or more of:<\/p>\n<ul>\n<li>You have files missing from your workspace that need replaced.<\/li>\n<li>You have locally modified (i.e. not opened for edit) files that need replaced.<\/li>\n<li>These files are large in either size or number, and on a slow or remote server, so a complete force-sync is not an appealing option.<\/li>\n<\/ul>\n<p>Normally this could easily be solved with something like\u00a0<em>p4 diff -sd\/-se \/\/depot\/path\/.. | p4 -x \u2013 sync -f<\/em>, which finds all the missing\/outdated files and then force-syncs them.<\/p>\n<p>The problem with this approach comes when you need the files from a specific revision or label. While you can pass in a label\/revision to &#8216;p4 diff&#8217;, the sync part will always retrieve the latest version of a file. To fix this we need to save the list of files we need to a temporary location, then postfix each line with the version we want, then feed that new list back to p4 sync.<\/p>\n<p>But there&#8217;s one final catch. If your filenames are local paths instead of Perforce paths, you cannot specify a label, only revisions. E.g. c:\\temp\\foo.dat@SOME_LABEL will not work, but c:\\temp\\foo.dat#999 will. Fortunately we can use the pseudo revision &#8216;have&#8217; for our purposes.<\/p>\n<p><em>@echo off<\/em><\/p>\n<p><em>REM Could optionally pass these as %1 and %2 from the cmd line<br \/>\nset LABEL=@SOME_LABEL<br \/>\nset BASE_DIR=\/\/depot\/path\/\u2026<\/em><\/p>\n<p><em>del p4sync.txt<\/em><\/p>\n<p><em>echo Setting &#8216;have&#8217; to %LABEL% for %BASE_DIR%<br \/>\nREM do a nop sync that sets our &#8216;have&#8217; version to the label we want<br \/>\np4 sync -k %BASE_DIR%%LABEL%<\/em><\/p>\n<p><em>echo Finding modified files..<br \/>\np4 diff -se %BASE_DIR%%LABEL% &gt; p4diff.txt<\/em><\/p>\n<p><em>echo Finding missing files..<br \/>\np4 diff -sd %BASE_DIR%%LABEL% &gt;&gt; p4diff.txt<\/em><\/p>\n<p><em>echo Building sync commands<br \/>\nREM Append #have to each filename and put them all in a list of files to sync<br \/>\nfor \/f %%i in (p4diff.txt) Do echo %%i#have&gt;&gt; p4sync.txt<\/em><\/p>\n<p><em>REM Now sync everything<br \/>\nif exist p4sync.txt (<br \/>\necho Syncing..<br \/>\np4 -x p4sync.txt sync -f<br \/>\n)else (<br \/>\necho It seems no files need updated!<br \/>\n)<\/em><\/p>\n<p>Voila!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I think this is the 5th time I&#8217;ve had to figure this out in the past few years, so this [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[22],"tags":[273,832,2916,4471,472,373,1912],"class_list":["post-4543","post","type-post","status-publish","format-standard","hentry","category-perforce","tag-files","tag-find","tag-missing","tag-missing-modified-files","tag-modified","tag-perforce","tag-sync"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Syncing missing\/modified files to a specific version in Perforce - scmGalaxy<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.scmgalaxy.com\/tutorials\/syncing-missing-modified-files-to-a-specific-version-in-perforce\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Syncing missing\/modified files to a specific version in Perforce - scmGalaxy\" \/>\n<meta property=\"og:description\" content=\"I think this is the 5th time I&#8217;ve had to figure this out in the past few years, so this [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.scmgalaxy.com\/tutorials\/syncing-missing-modified-files-to-a-specific-version-in-perforce\/\" \/>\n<meta property=\"og:site_name\" content=\"scmGalaxy\" \/>\n<meta property=\"article:published_time\" content=\"2018-01-08T12:00:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-02-27T09:09:54+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.andrewgrant.org\/wordpress\/wp-includes\/images\/smilies\/icon_smile.gif\" \/>\n<meta name=\"author\" content=\"scmgalaxy K\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"scmgalaxy K\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/syncing-missing-modified-files-to-a-specific-version-in-perforce\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/syncing-missing-modified-files-to-a-specific-version-in-perforce\\\/\"},\"author\":{\"name\":\"scmgalaxy K\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/fc12ad190f540e79460243c81148d102\"},\"headline\":\"Syncing missing\\\/modified files to a specific version in Perforce\",\"datePublished\":\"2018-01-08T12:00:29+00:00\",\"dateModified\":\"2021-02-27T09:09:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/syncing-missing-modified-files-to-a-specific-version-in-perforce\\\/\"},\"wordCount\":402,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/syncing-missing-modified-files-to-a-specific-version-in-perforce\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.andrewgrant.org\\\/wordpress\\\/wp-includes\\\/images\\\/smilies\\\/icon_smile.gif\",\"keywords\":[\"files\",\"Find\",\"Missing\",\"Missing\\\/modified files\",\"modified\",\"Perforce\",\"sync\"],\"articleSection\":[\"Perforce\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/syncing-missing-modified-files-to-a-specific-version-in-perforce\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/syncing-missing-modified-files-to-a-specific-version-in-perforce\\\/\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/syncing-missing-modified-files-to-a-specific-version-in-perforce\\\/\",\"name\":\"Syncing missing\\\/modified files to a specific version in Perforce - scmGalaxy\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/syncing-missing-modified-files-to-a-specific-version-in-perforce\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/syncing-missing-modified-files-to-a-specific-version-in-perforce\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.andrewgrant.org\\\/wordpress\\\/wp-includes\\\/images\\\/smilies\\\/icon_smile.gif\",\"datePublished\":\"2018-01-08T12:00:29+00:00\",\"dateModified\":\"2021-02-27T09:09:54+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/fc12ad190f540e79460243c81148d102\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/syncing-missing-modified-files-to-a-specific-version-in-perforce\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/syncing-missing-modified-files-to-a-specific-version-in-perforce\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/syncing-missing-modified-files-to-a-specific-version-in-perforce\\\/#primaryimage\",\"url\":\"http:\\\/\\\/www.andrewgrant.org\\\/wordpress\\\/wp-includes\\\/images\\\/smilies\\\/icon_smile.gif\",\"contentUrl\":\"http:\\\/\\\/www.andrewgrant.org\\\/wordpress\\\/wp-includes\\\/images\\\/smilies\\\/icon_smile.gif\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/syncing-missing-modified-files-to-a-specific-version-in-perforce\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Syncing missing\\\/modified files to a specific version in Perforce\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\",\"name\":\"scmGalaxy\",\"description\":\"A Platform for Software Engineers\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/fc12ad190f540e79460243c81148d102\",\"name\":\"scmgalaxy K\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b902ea8c77ee0a326c112f29d0edf51b7c3e1cd05c4fb92a810177e9c3f12a9?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b902ea8c77ee0a326c112f29d0edf51b7c3e1cd05c4fb92a810177e9c3f12a9?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b902ea8c77ee0a326c112f29d0edf51b7c3e1cd05c4fb92a810177e9c3f12a9?s=96&d=mm&r=g\",\"caption\":\"scmgalaxy K\"},\"sameAs\":[\"http:\\\/\\\/www.DevOpsSchool.com\"],\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/author\\\/scmgalaxy\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Syncing missing\/modified files to a specific version in Perforce - scmGalaxy","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.scmgalaxy.com\/tutorials\/syncing-missing-modified-files-to-a-specific-version-in-perforce\/","og_locale":"en_US","og_type":"article","og_title":"Syncing missing\/modified files to a specific version in Perforce - scmGalaxy","og_description":"I think this is the 5th time I&#8217;ve had to figure this out in the past few years, so this [&hellip;]","og_url":"https:\/\/www.scmgalaxy.com\/tutorials\/syncing-missing-modified-files-to-a-specific-version-in-perforce\/","og_site_name":"scmGalaxy","article_published_time":"2018-01-08T12:00:29+00:00","article_modified_time":"2021-02-27T09:09:54+00:00","og_image":[{"url":"http:\/\/www.andrewgrant.org\/wordpress\/wp-includes\/images\/smilies\/icon_smile.gif","type":"","width":"","height":""}],"author":"scmgalaxy K","twitter_card":"summary_large_image","twitter_misc":{"Written by":"scmgalaxy K","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/syncing-missing-modified-files-to-a-specific-version-in-perforce\/#article","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/syncing-missing-modified-files-to-a-specific-version-in-perforce\/"},"author":{"name":"scmgalaxy K","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/fc12ad190f540e79460243c81148d102"},"headline":"Syncing missing\/modified files to a specific version in Perforce","datePublished":"2018-01-08T12:00:29+00:00","dateModified":"2021-02-27T09:09:54+00:00","mainEntityOfPage":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/syncing-missing-modified-files-to-a-specific-version-in-perforce\/"},"wordCount":402,"commentCount":0,"image":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/syncing-missing-modified-files-to-a-specific-version-in-perforce\/#primaryimage"},"thumbnailUrl":"http:\/\/www.andrewgrant.org\/wordpress\/wp-includes\/images\/smilies\/icon_smile.gif","keywords":["files","Find","Missing","Missing\/modified files","modified","Perforce","sync"],"articleSection":["Perforce"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.scmgalaxy.com\/tutorials\/syncing-missing-modified-files-to-a-specific-version-in-perforce\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/syncing-missing-modified-files-to-a-specific-version-in-perforce\/","url":"https:\/\/www.scmgalaxy.com\/tutorials\/syncing-missing-modified-files-to-a-specific-version-in-perforce\/","name":"Syncing missing\/modified files to a specific version in Perforce - scmGalaxy","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/syncing-missing-modified-files-to-a-specific-version-in-perforce\/#primaryimage"},"image":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/syncing-missing-modified-files-to-a-specific-version-in-perforce\/#primaryimage"},"thumbnailUrl":"http:\/\/www.andrewgrant.org\/wordpress\/wp-includes\/images\/smilies\/icon_smile.gif","datePublished":"2018-01-08T12:00:29+00:00","dateModified":"2021-02-27T09:09:54+00:00","author":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/fc12ad190f540e79460243c81148d102"},"breadcrumb":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/syncing-missing-modified-files-to-a-specific-version-in-perforce\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.scmgalaxy.com\/tutorials\/syncing-missing-modified-files-to-a-specific-version-in-perforce\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/syncing-missing-modified-files-to-a-specific-version-in-perforce\/#primaryimage","url":"http:\/\/www.andrewgrant.org\/wordpress\/wp-includes\/images\/smilies\/icon_smile.gif","contentUrl":"http:\/\/www.andrewgrant.org\/wordpress\/wp-includes\/images\/smilies\/icon_smile.gif"},{"@type":"BreadcrumbList","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/syncing-missing-modified-files-to-a-specific-version-in-perforce\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.scmgalaxy.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Syncing missing\/modified files to a specific version in Perforce"}]},{"@type":"WebSite","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website","url":"https:\/\/www.scmgalaxy.com\/tutorials\/","name":"scmGalaxy","description":"A Platform for Software Engineers","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.scmgalaxy.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/fc12ad190f540e79460243c81148d102","name":"scmgalaxy K","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b902ea8c77ee0a326c112f29d0edf51b7c3e1cd05c4fb92a810177e9c3f12a9?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b902ea8c77ee0a326c112f29d0edf51b7c3e1cd05c4fb92a810177e9c3f12a9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b902ea8c77ee0a326c112f29d0edf51b7c3e1cd05c4fb92a810177e9c3f12a9?s=96&d=mm&r=g","caption":"scmgalaxy K"},"sameAs":["http:\/\/www.DevOpsSchool.com"],"url":"https:\/\/www.scmgalaxy.com\/tutorials\/author\/scmgalaxy\/"}]}},"_links":{"self":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/4543","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/comments?post=4543"}],"version-history":[{"count":1,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/4543\/revisions"}],"predecessor-version":[{"id":4544,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/4543\/revisions\/4544"}],"wp:attachment":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/media?parent=4543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/categories?post=4543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/tags?post=4543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}