Git:如何在推送到远程目录时进行更新? [英] Git: how to make remote directory update when pushed to?

查看:142
本文介绍了Git:如何在推送到远程目录时进行更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用git来管理远程服务器上的一些数据,因此我在那里设置了一个非裸存储库。我可以毫无问题地推送它,并且存储库本身会更新,但实际文件不会被更改/添加/删除。我必须ssh进入服务器并执行

  git reset --hard HEAD 

来获得文件结构以实际更新。



要做什么?

解决方案

您不应该这样做。建议使用裸存储库。换句话说,没有文件检出,只是.git目录本身。然后,您可以将存储库检出到服务器上的其他位置 - 比如说您的web根目录。这样,您就可以得到:


  • git最佳做法。根据Git文档,如果你不遵守它,你可能会得到意想不到的结果。任何完成了编程的人都知道,意想不到的结果是代码可能会吃掉你的孩子,应该不惜一切代价避免。

  • 如果您计划通过网络服务器访问服务器上的已检出文件,则可以提高安全性。 能够对实时签出的代码进行快速更改。您可以尝试直接在存储库上执行此操作,但这会很麻烦并且更容易出错。
  • 更新独立于更新的服务器存储库的能力您的实时服务代码。这非常重要,如果您正在远程工作并需要向服务器发送某些内容,然后在准备好实时服务之前做进一步工作,或者如果您的实时服务代码发生更改(例如,不同的配置设置),并需要将这些更改与回购协议中的更改合并,但现在无法完成。




我推荐以下步骤:


  • 按照git文档设置裸仓

  • 检查你的代码库到你的实时服务目标dir

  • 设置一个git钩子(post-commit应该是正确的一个IIRC)来更新你的实时服务。它应该可以cd到实时服务目录,然后做一个git pull --rebase,并设置一些文件许可权。

  • 从现在开始,将代码从您的开发箱推送到回购站。


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?

解决方案

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.

这篇关于Git:如何在推送到远程目录时进行更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆