问题
I used this guide to use git to autopublish my changes on my website when I push to my remote origin git repository:
http://www.lwp.ca/james/2010/03/using-git-to-manage-online-website-projects/
Here's my /hooks/post-update file:
cd ../../public_html/dir/wbg
env -i git pull
Here's my directory structure:
/home/git/wbg.git <-- my remote git repository
/home/public_html/dir/wbg <-- my web folder
When I run
git push origin master
The repository updates but my web folder is still empty. Any ideas?
Edit: if any future traffic sees this, my real problem was that BOTH your remote origin AND your destination website directory must be git repositories. You can't just set it up to copy your project to a new folder unless that folder is also a git repo.
回答1:
Not a lot to go off of here, but I can report that I successfully use a similar method to this.
For my purposes, I call my bare server repository the "Hub" and my web-facing repository the "Prime". Make sure that you have properly initialized a git repository in your server htdocs directory (Prime) and have either pushed the changes to the bare repository (Hub) or pulled them in.
This is the post-update
hook I use, which is in my Hub repository's hooks directory:
#!/bin/sh
echo
echo "*** Pulling changes into Prime"
echo
cd /path/to/htdocs/ || exit
unset GIT_DIR
git pull hub master
exec git-update-server-info
Make sure this is executable! If in doubt, just edit the post-update.sample
file and remove the .sample
extension when done. The echoed text gives nice feedback that the copying is actually taking place. If you don't see that text, then it's not pulling the changes. And if you're not going to call your remote repository "hub", replace it with "origin" or whatever you decide to use.
As a precaution so that my Prime and local repositories don't get too out of whack, I have this as my Prime post-commit
hook:
#!/bin/sh
echo
echo "*** Pushing changes to Hub"
echo
git push hub
Then I can just pull the changes from Hub into my local repository.
回答2:
You can find a better alternative at http://toroid.org/ams/git-website-howto that only uses one git repository, and allows all metadata and previous history to remain outside of the DocumentRoot.
The guide you used and the one I linked referrer to another article both are based on, but the one I linked seems to be the preferred one to direct new users to in the #git IRC channel.
回答3:
You might start by getting post-update to echo some debugging output. Both standard output and standard error output are forwarded to git send-pack on the other end, so you can simply echo messages and you will see these on the client that you did git push. I assume you followed the guide to the word, made the post-update script executable, cloned the repo to the web folder etc.
来源:https://stackoverflow.com/questions/4938239/using-git-to-publish-to-a-website