{"id":1052,"date":"2014-01-07T17:17:00","date_gmt":"2014-01-07T09:17:00","guid":{"rendered":"http:\/\/blog.dayandcarrot.net\/?p=1052"},"modified":"2014-01-07T17:17:00","modified_gmt":"2014-01-07T09:17:00","slug":"ftp%e6%98%af90%e5%b9%b4%e4%bb%a3%e7%9a%84%ef%bc%8c%e4%bd%bf%e7%94%a8git%e5%8f%96%e4%bb%a3%e5%ae%83%e6%9d%a5%e9%83%a8%e7%bd%b2%e4%bb%a3%e7%a0%81%e5%90%a7","status":"publish","type":"post","link":"https:\/\/dayandcarrot.space\/?p=1052","title":{"rendered":"FTP\u662f90\u5e74\u4ee3\u7684\uff0c\u4f7f\u7528Git\u53d6\u4ee3\u5b83\u6765\u90e8\u7f72\u4ee3\u7801\u5427"},"content":{"rendered":"<p>\u539f\u6587\uff1a<a href=\"https:\/\/coderwall.com\/p\/xczkaq?&amp;p=1&amp;q=\" target=\"_blank\" rel=\"noopener noreferrer\">FTP is so 90&#8217;s. Let&#8217;s deploy via Git instead!<\/a><br \/>\n\u8bd1\u8005\uff1a<a href=\"https:\/\/github.com\/youngsterxyf\" target=\"_blank\" rel=\"noopener noreferrer\">youngsterxyf<\/a><br \/>\n\u9996\u5148\uff0c\u5728\u4f60\u7684\u670d\u52a1\u5668\u4e0a\u521b\u5efa\u4e00\u4e2a\u76ee\u5f55\uff0c\u5e76\u5728\u5176\u4e2d\u521d\u59cb\u5316\u4e00\u4e2a\u7a7a\u7684git\u4ed3\u5e93\u3002\u6211\u559c\u6b22\u4f7f\u7528<code>~\/www\/<\/code>\u76ee\u5f55\u6765\u5b58\u653e\u7f51\u7ad9\u4ee3\u7801\uff0c \u56e0\u6b64\u6211\u4f1a\u8fd9\u4e48\u505a\uff1a<\/p>\n<div>\n<pre>mkdir ~\/www\/example.com &amp;&amp; cd ~\/www\/example.com\ngit init<\/pre>\n<\/div>\n<p>\u63a5\u7740\uff0c\u8bbe\u7f6e\u4f60\u670d\u52a1\u5668\u4e0a\u7684git\u4ed3\u5e93\u4ee5\u4fbf\u5f88\u597d\u5730\u901a\u8fc7<code>git push<\/code>\u6765\u90e8\u7f72\u4ee3\u7801\u3002<\/p>\n<div>\n<pre>git config core.worktree ~\/www\/example.com\ngit config receive.denycurrentbranch ignore<\/pre>\n<\/div>\n<p>\u6700\u540e\uff0c\u4e3agit\u8bbe\u7f6e\u4e00\u4e2apost-receive\u94a9\u5b50\u6765\u68c0\u51fa<code>master<\/code>\u5206\u652f\uff0c\u8fd9\u6837\uff0c\u4f60\u7684web\u670d\u52a1\u5668\u5c31\u53ef\u4ee5\u4e3a\u90a3\u4e2a\u5206\u652f\u7684\u4ee3\u7801\u6587\u4ef6\u670d\u52a1\u4e86\u3002 \uff08\u8bb0\u4f4f\uff0c<code>^D<\/code>\u662fControl+D\uff0c\u6216\u4efb\u4f55\u4e00\u79cd\u4f60shell\u7684<a href=\"http:\/\/en.wikipedia.org\/wiki\/End-of-transmission_character\">EOT\u5b57\u7b26<\/a>\uff09\u3002<\/p>\n<div>\n<pre>cat &gt; .git\/hooks\/post-receive\n#!\/bin\/sh\ngit checkout -f\n^D\nchmod +x .git\/hooks\/post-receive<\/pre>\n<\/div>\n<p>\u8c28\u8bb0\uff1a\u82e5\u9700\u8981\u4e00\u4e2a\u6784\u5efa\u8fc7\u7a0b\uff0c\u4f60\u53ef\u4ee5\u5728post-receive\u94a9\u5b50\u4e2d\u6dfb\u52a0\u4efb\u4f55\u4f60\u60f3\u8981\u6dfb\u52a0\u7684\u4e1c\u897f\u3002\u4f8b\u5982\uff0c\u6211\u7684sinatra\u9879\u76ee\u5176\u4e2d\u4e4b\u4e00\u4f7f\u7528\u4e86\u5982\u4e0b\u7684 post-receive\u94a9\u5b50\uff1a<\/p>\n<div>\n<pre>#!\/bin\/sh\ngit checkout -f\nbundle install\ntouch ~\/www\/example.com\/tmp\/restart.txt<\/pre>\n<\/div>\n<p>\u56de\u5230\u4f60\u7684\u672c\u5730\u673a\u5668\uff0c\u4e3a\u4ee3\u7801\u90e8\u7f72\u51c6\u5907\u597d\u4f60\u7684git\u4ed3\u5e93\u3002<\/p>\n<div>\n<pre>cd ~\/www\/dev\/example.com\ngit remote add origin\nssh:\/\/user@example.com\/home\/user\/www\/example.com<\/pre>\n<\/div>\n<p>\u5bf9\u4e8e\u7b2c\u4e00\u6b21\u63a8\u9001\u4ee3\u7801\u5230\u670d\u52a1\u5668\uff0c\u6267\u884c\u5982\u4e0b\u547d\u4ee4\u3002<\/p>\n<div>\n<pre>git push origin master<\/pre>\n<\/div>\n<p>\u73b0\u5728\uff0c\u4efb\u4f55\u65f6\u5019\u4f60\u60f3\u90e8\u7f72\u672c\u5730\u7684\u53d8\u66f4\uff0c\u53ea\u8981\u7b80\u5355\u5730\u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff01<\/p>\n<div>\n<pre>git push<\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\uff1aFTP is so 90&#8217;s. Let&#8217;s deploy via Git instead! \u8bd1\u8005\uff1ayoungsterxyf \u9996\u5148\uff0c\u5728\u4f60\u7684\u670d\u52a1\u5668\u4e0a\u521b\u5efa\u4e00\u4e2a\u76ee\u5f55\uff0c\u5e76\u5728\u5176\u4e2d\u521d\u59cb\u5316\u4e00\u4e2a\u7a7a\u7684git\u4ed3\u5e93\u3002\u6211\u559c\u6b22\u4f7f\u7528~\/www\/\u76ee\u5f55\u6765\u5b58\u653e\u7f51\u7ad9\u4ee3\u7801\uff0c \u56e0\u6b64\u6211\u4f1a\u8fd9\u4e48\u505a\uff1a mkdir ~\/www\/example.com &amp;&amp; cd ~\/www\/example.com git init \u63a5\u7740\uff0c\u8bbe\u7f6e\u4f60\u670d\u52a1\u5668\u4e0a\u7684git\u4ed3\u5e93\u4ee5\u4fbf\u5f88\u597d\u5730\u901a\u8fc7git push\u6765\u90e8\u7f72\u4ee3\u7801\u3002 git config core.worktree ~\/www\/example.com git config receive.denycurrentbranch ignore \u6700\u540e\uff0c\u4e3agit\u8bbe\u7f6e\u4e00\u4e2apost-receive\u94a9\u5b50\u6765\u68c0\u51famaster\u5206\u652f\uff0c\u8fd9\u6837\uff0c\u4f60\u7684web\u670d\u52a1\u5668\u5c31\u53ef\u4ee5\u4e3a\u90a3\u4e2a\u5206\u652f\u7684\u4ee3\u7801\u6587\u4ef6\u670d\u52a1\u4e86\u3002 \uff08\u8bb0\u4f4f\uff0c^D\u662fControl+D\uff0c\u6216\u4efb\u4f55\u4e00\u79cd\u4f60shell\u7684EOT\u5b57\u7b26\uff09\u3002 cat &gt; .git\/hooks\/post-receive #!\/bin\/sh git checkout -f ^D chmod +x .git\/hooks\/post-receive \u8c28\u8bb0\uff1a\u82e5\u9700\u8981\u4e00\u4e2a\u6784\u5efa\u8fc7\u7a0b\uff0c\u4f60\u53ef\u4ee5\u5728post-receive\u94a9\u5b50\u4e2d\u6dfb\u52a0\u4efb\u4f55\u4f60\u60f3\u8981\u6dfb\u52a0\u7684\u4e1c\u897f\u3002\u4f8b\u5982\uff0c\u6211\u7684sinatra\u9879\u76ee\u5176\u4e2d\u4e4b\u4e00\u4f7f\u7528\u4e86\u5982\u4e0b\u7684 post-receive\u94a9\u5b50\uff1a #!\/bin\/sh git checkout -f bundle install touch ~\/www\/example.com\/tmp\/restart.txt \u56de\u5230\u4f60\u7684\u672c\u5730\u673a\u5668\uff0c\u4e3a\u4ee3\u7801\u90e8\u7f72\u51c6\u5907\u597d\u4f60\u7684git\u4ed3\u5e93\u3002 cd ~\/www\/dev\/example.com [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[47],"class_list":["post-1052","post","type-post","status-publish","format-standard","hentry","category-technical","tag-git"],"_links":{"self":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/1052","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1052"}],"version-history":[{"count":0,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/1052\/revisions"}],"wp:attachment":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1052"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1052"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1052"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}