{"id":1284,"date":"2016-08-01T11:12:03","date_gmt":"2016-08-01T21:12:03","guid":{"rendered":"http:\/\/mymonkeydo.com\/?p=1284"},"modified":"2020-05-03T16:33:44","modified_gmt":"2020-05-04T02:33:44","slug":"git-copy","status":"publish","type":"post","link":"https:\/\/mymonkeydo.com\/git-copy\/","title":{"rendered":"Git Copy"},"content":{"rendered":"

This may be\u00a0obvious to the git experts, but I am not that. \u00a0There also may be a better way to do this, but again, not a git expert.<\/p>\n

I have a git repo set up on WPEngine<\/a>, but they only allow the whole server to be a repo, not just a single plugin. \u00a0This was a problem since the whole server directory was not in my current repo.\u00a0 So it was either make a new repo which was basically a copy of my current repo but a different folder structure\u00a0or keep on using SFTP. \u00a0I decided to make a new duplicate repo. \u00a0The problem (which i also had with SFTP) was finding the files that changed and pushing them to the server. \u00a0This is both error-prone and slow. \u00a0I found a script that could copy all changed files from the last commit into my WPEngine\u00a0deploy directory and also\u00a0discovered a way to do this automatically when pushing from my main repo.<\/p>\n

Create\/Save this script in .git\/hooks\/pre-push file. \u00a0This would be in the main git repo I work in. \u00a0This copies all changed files to the WPEngine deployment repo.
\n
\n#!\/bin\/bash<\/code><\/p>\n

TARGET=”\/your\/deployment\/path”
\nMOST_RECENT=$(git log -n 1 –pretty=format:’%h’)
\nPREV=$(git log –skip=1 -n 1 –pretty=format:’%h’)<\/p>\n

echo “Coping to $TARGET”
\nfor i in $(git diff –name-only $MOST_RECENT $PREV)
\ndo
\n# First create the target directory, if it doesn’t exist.
\nmkdir -p “$TARGET\/$(dirname $i)”
\n# Then copy over the file.
\ncp “$i” “$TARGET\/$i”
\ndone
\nexit 0<\/p>\n

Thanks to the following articles about pre-push hooks and how to get the files\u00a0between commits.<\/p>\n

http:\/\/www.phprepo.in\/2012\/04\/git-copy-all-changed-files-between-two-commits-with-directory-structure\/<\/p>\n

http:\/\/blog.ittybittyapps.com\/blog\/2013\/09\/03\/git-pre-push\/<\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[6],"tags":[],"yoast_head":"\nGit Copy - My Monkey Do<\/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:\/\/mymonkeydo.com\/git-copy\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Git Copy - My Monkey Do\" \/>\n<meta property=\"og:url\" content=\"https:\/\/mymonkeydo.com\/git-copy\/\" \/>\n<meta property=\"og:site_name\" content=\"My Monkey Do\" \/>\n<meta property=\"article:published_time\" content=\"2016-08-01T21:12:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-05-04T02:33:44+00:00\" \/>\n<meta name=\"author\" content=\"Webhead\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Webhead\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/mymonkeydo.com\/git-copy\/\",\"url\":\"https:\/\/mymonkeydo.com\/git-copy\/\",\"name\":\"Git Copy - My Monkey Do\",\"isPartOf\":{\"@id\":\"https:\/\/mymonkeydo.com\/#website\"},\"datePublished\":\"2016-08-01T21:12:03+00:00\",\"dateModified\":\"2020-05-04T02:33:44+00:00\",\"author\":{\"@id\":\"https:\/\/mymonkeydo.com\/#\/schema\/person\/b16fc650a8c182faaac896bab099b829\"},\"breadcrumb\":{\"@id\":\"https:\/\/mymonkeydo.com\/git-copy\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/mymonkeydo.com\/git-copy\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/mymonkeydo.com\/git-copy\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/mymonkeydo.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Git Copy\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/mymonkeydo.com\/#website\",\"url\":\"https:\/\/mymonkeydo.com\/\",\"name\":\"My Monkey Do\",\"description\":\"A Log of Coding Solutions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/mymonkeydo.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/mymonkeydo.com\/#\/schema\/person\/b16fc650a8c182faaac896bab099b829\",\"name\":\"Webhead\",\"url\":\"https:\/\/mymonkeydo.com\/author\/corey\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Git Copy - My Monkey Do","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:\/\/mymonkeydo.com\/git-copy\/","og_locale":"en_US","og_type":"article","og_title":"Git Copy - My Monkey Do","og_url":"https:\/\/mymonkeydo.com\/git-copy\/","og_site_name":"My Monkey Do","article_published_time":"2016-08-01T21:12:03+00:00","article_modified_time":"2020-05-04T02:33:44+00:00","author":"Webhead","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Webhead","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/mymonkeydo.com\/git-copy\/","url":"https:\/\/mymonkeydo.com\/git-copy\/","name":"Git Copy - My Monkey Do","isPartOf":{"@id":"https:\/\/mymonkeydo.com\/#website"},"datePublished":"2016-08-01T21:12:03+00:00","dateModified":"2020-05-04T02:33:44+00:00","author":{"@id":"https:\/\/mymonkeydo.com\/#\/schema\/person\/b16fc650a8c182faaac896bab099b829"},"breadcrumb":{"@id":"https:\/\/mymonkeydo.com\/git-copy\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/mymonkeydo.com\/git-copy\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/mymonkeydo.com\/git-copy\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/mymonkeydo.com\/"},{"@type":"ListItem","position":2,"name":"Git Copy"}]},{"@type":"WebSite","@id":"https:\/\/mymonkeydo.com\/#website","url":"https:\/\/mymonkeydo.com\/","name":"My Monkey Do","description":"A Log of Coding Solutions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/mymonkeydo.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/mymonkeydo.com\/#\/schema\/person\/b16fc650a8c182faaac896bab099b829","name":"Webhead","url":"https:\/\/mymonkeydo.com\/author\/corey\/"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/posts\/1284"}],"collection":[{"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/comments?post=1284"}],"version-history":[{"count":0,"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/posts\/1284\/revisions"}],"wp:attachment":[{"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/media?parent=1284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/categories?post=1284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mymonkeydo.com\/wp-json\/wp\/v2\/tags?post=1284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}