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

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

问题描述

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

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.

要做什么?

推荐答案

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

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 最佳实践.根据 Git 文档,如果你不遵循它,你可能会得到意想不到的结果".任何编程经验丰富的人都知道,意外结果"是可能会吃掉你的孩子,应该不惜一切代价避免"的代码.

  • 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.

我建议执行以下步骤:

  • 按照 git 文档设置裸仓库
  • 将代码从您的存储库签出到您的实时服务目标目录
  • 设置一个 git 钩子(post-commit 应该是正确的 IIRC)以在更新存储库时更新您的实时服务.它可能应该 cd 到实时服务目录,然后执行 git pull --rebase,并可能设置一些文件权限.
  • 从现在开始,只需将您的代码从您的开发箱推送到存储库.

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

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