问题
I have a website that is running on a Windows 2008 server. I want to know what is the best way to manage that site using git. Ideally I want an automated deployment, using a post-receive hook or similar.
I do have a Linux server that I typically use as my git origin server, so I can utilize that if it makes things easier. Typically my post-receive file there looks like this:
#!/bin/sh
GIT_WORK_TREE=/var/www/example.com git checkout -f
Obviously that won't work as-is on Windows without something else in place.
My Windows server supports FTP but I'd like to use something more secure if possible.
回答1:
I ended up using these instructions to setup Cygwin + OpenSSH + Git which got me most of the way there.
http://www.shannoncornish.com/blog/2009/04/git-server-windows-2008/
In the post-receive I had to remove the first line #!/bin/sh
due to some permission issues, and I added a symlink to my webroot from within Cygwin like so:
ln -s /cygdrive/c/inetpub/wwwroot /var/www
So the post-receive file ended up looking very similar to before but without the first line
GIT_WORK_TREE=/var/www/example.com git checkout -f
回答2:
You can use a Windows path in your bash script (which will be interpreted by msysgit on windows).
/C/my/path/...
You can see here an example of a fairly complex post-checkout hook (not a post-receive, but it can illustrates what you can do on Windows in a bash hook script).
More details in "Combining mingw and git".
Actually, Adam Rofer mentions in the comments:
If you use normal windows sharing, you can access git repositories via this path syntax:
//computername/folder/repo.git
assuming folder is the shared folder accessible to your login via normal windows folder sharing. Msysgit seems to play well with this.
来源:https://stackoverflow.com/questions/9198397/managing-website-on-windows-using-git