Migrating a production site with no VCS at all to Git

半城伤御伤魂 提交于 2019-12-09 18:34:18

问题


I thought I would throw this out there and see if I could get some solid advice on this.

I've got a production site with a rather large code base and have just installed Git on it, same with test site. And I've got a local box that will basically be the point of integration. Our team will push to the local box and little gnomes will come and take everything off to our different servers - or at least that's the closest I've come to implementing Git.

I really don't have the slightest clue where to begin. I've got a big, finicky, legacy codebase that I am scared to touch on a good day. Git is meant to be the starting point of a big cleanup process, I just don't know how to get started.

I was thinking of creating a bare .git repo based on my production docroot (with applicable .gitignore stuff) and then cloning over to test and development environments, then individuals would clone off dev and get to work, pushing back to dev and then somehow magically telling git to update the docroot when changes to the bare repo are made.

I was going to install git-flow on development (can't get it to work on my production server), and then push to production. Since they are just branches at the end of the day, figured I could get away with not using git-flow on prod/test servers.

This seems all well and good, I just don't know if I should be pushing to test/prod, or pulling from dev to test/prod. Maybe just a straight git init in production docroot? Create a .git directory and git init to that? Git init git giggidy giggigdy...

Insights are appreciated.

Edit

Here's what I ended up doing, hopefully someone else will find it useful.

Downloaded current production code to development server (LAMP) Set up .gitignore files and ran git init within the directory and peformed initial import/commit
On Staging/Production servers:
Created YOURNAME.git directories and created bare repositories with git init --bare
Set worktree as /path/to/my/public_html, set bare to false, and set receive.denycurrentbranch to ignore
Added a line to hooks/post-receive: git checkout -f making sure that my git user had permission to write to the worktrees

Back on the development server:
git remote add [staging|production] ssh://myuser@myserver/path/to/my.git
git push [staging|production] master

To update my production and staging sites, its a simple git push [production|staging] and I don't have to fuss with hiding a .git directory from public view.

Sources: http://www.deanoj.co.uk/programming/git/using-git-and-a-post-receive-hook-script-for-auto-deployment/
http://toroid.org/ams/git-website-howto

Hope this helps someone!

Edit again
Also, works best on 1.7.3.3 or later. I'm running a virtualized ubuntu box for development and ran into some issues committing over Samba. After fighting with this for a couple of hours, read that the issue was fixed in 1.7.3.3. I was on 1.7.3.1.


回答1:


If you're not interested in getting into the heavier deployment solutions like Capistrano then you can set up a post-receive hook on your bare repository that checks out the latest changes into your production docroot. You could set up a separate hook for both dev and for production. Here is a pretty good guide to doing this.



来源:https://stackoverflow.com/questions/5835997/migrating-a-production-site-with-no-vcs-at-all-to-git

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!