Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
454 views
in Technique[技术] by (71.8m points)

version control - Git: how to make remote directory update when pushed to?

I want to use git to manage some data on a remote server, so I set up a non-bare repository there. I can push to it without problems, and the repository itself updates but the actual files are not changed/added/deleted. I have to ssh into the server and do a

git reset --hard HEAD

to get the file structure to actually update.

What's to be done?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You shouldn't do this. It's recommended to have bare repositories. In other words, no files checked out, just the .git directory itself. You can then checkout the repository to some other location on your server -- say, your web root. This way, you get:

  • git best practice. According to the Git docs, you can get "unexpected results" if you don't follow it. Anyone who's done a good bit of programming knows that "unexpected results" is code for "will probably eat your children and should be avoided at all costs."

  • better security, if you're planning to have the checked out files on the server accessible from a webserver.

  • Local modifications on your checked-out code, and the ability to make quick changes on the live checked out code. You could attempt to do this directly on the repository, but it would be messy and more prone to error.

  • The ability to update your server repository independently of updating your live service code. This is pretty crucial, if you're working remotely and need to send something to the server and then do further work before it will be ready for your live service, or if you have changes in your live service code (say, different configuration settings) and need to merge those changes with the changes in the repo, but can't do it just now.

I'd recommend the following steps:

  • Follow the git docs on setting up a bare repository
  • Check out code from your repo to your live service target dir
  • Setup a git hook (post-commit should be the right one IIRC) to update your live service when the repository is updated. It should probably cd to the live service dir, and do a git pull --rebase, and maybe set some file permissions.
  • Just push your code to the repo from your dev box from now on.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...