我使用rsync同步我的本地计算机的内容与服务器,如果你只是部署到一台服务器,那么它很简单(和Capistrano是矫枉过正。)。我把下面的别名在~/.bash_profile
:
alias eget='rsync -avie ssh [email protected]:sites/example.com/www/ ~/Projects/example/example.com/www/ --exclude .DS_Store --exclude ".git*" --delete-after'
alias edep='rsync -avuie ssh ~/Projects/example/example.com/www/ [email protected]:sites/example.com/www/ --exclude .DS_Store --exclude ".git*" --delay-updates --delete-after'
然后,从混帐回购协议我的本地机器上。我做的:
git commit -am 'commit some changes'
git pull --rebase # pull any new changes from remote (--rebase prevents an unnecessary merge commit.)
eget -n # confirm which files I've changed
如果它看起来腥,我可以做eget
没有-n,然后就做了git diff -w
。然后,我可以为我想保留所做更改的文件做git checkout -- path/to/file
。然后,我提交服务器上的更改,这些更改我还没有完成。这只会在服务器上的文件以不同于部署的方式进行更改时才会发生。否则,您知道您的本地版本始终比服务器上的文件更新,因此不必担心在本地服务器上覆盖您尚未拥有的内容。继续...
edep -n # just see what files will be deployed/updated/etc.
edep # looks good. Deploy for real.
完成!
查看rsync(1) Mac OS X Manual Page了解更多信息。其他选项是使用Git post-receive hook。但是,你必须在服务器上安装Git才能做到这一点。另外,我建议把.git
目录放在你的公开目录www
之外,以保证安全&清洁的原因。您可以使用Git core.worktree
配置选项执行此操作。例如,从~/git/example.com.git
,做git init --bare; git config core.worktree ~/sites/example.com/
。这使得~/git/example.com.git
像.git
dir为~/sites/example.com/
。
检出http://stackoverflow.com/questions/279169/deploy-php-using-git – philfreo 2010-11-21 03:24:47
或Capistrano http://help.github.com/capistrano/ – philfreo 2010-11-21 03:25:06