我如何:Git单向推/不可编辑工作目录? [英] How do I: Git One Way Push / Uneditable Working Directory?

查看:122
本文介绍了我如何:Git单向推/不可编辑工作目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有两种机器的方法,比方说A和B.


  • A是我的本地机器,我在那里开发我的代码并推送它。

  • B是一台服务器,它永远不需要编辑代码,但需要一个工作目录。



是否有可能在没有 的情况下做任何 git pull 的任何事情?






我基本上只想使用git。在一个方向。有点像使用 rsync 将本地目录同步到远程目录,但使用版本控制。如果这对于git来说是不可能的,是否可以用其他方法?



再次,最好是使用版本控制。

解决方案

这篇文章解释得非常好。我将从那里复制代码。



假设您在服务器和工作站之间设置了SSH身份验证(无密码)。



在服务器上:

  mkdir website.git&& cd website.git 
git init --bare
mkdir /var/www/www.example.org
touch hooks / post-receive
chmod + x hooks / post-receive

然后把这个放在hooks / post-receive

 #!/ bin / sh 
GIT_WORK_TREE = / var / www / www.example.org git checkout -f






在您的本地git存储库中:

  git remote add web ssh://server.example.org/home/ams/website.git 
git push web + master:refs / heads / master






配置:


  • /var/www/www.example.org 是此网站的公共根。

  • / home / ams 是您创建的网站website.git

  • server.example.org 是服务器的域名,IP或主机别名 li>

Is there a way to have two machines, let's say A and B.

  • A is my local machine, where I develop my code, and push it.
  • B is a server, that will NEVER have to edit code, but NEEDS a working directory.

Is it possible to do this without doing any git pull's whatsoever from B?


I want to use git one way only, basically. In one direction. Sort of like using rsync to sync a local directory to a remote one, but with version control. If this isn't possible with git, is it possible with anything else?

Again, preferably with version control.

解决方案

This article explains it very well. I'll copy the code from there.

It assumes you have SSH authentication set up (no password) between your server and workstation.

On the server:

mkdir website.git && cd website.git
git init --bare
mkdir /var/www/www.example.org
touch hooks/post-receive
chmod +x hooks/post-receive

Then put this in hooks/post-receive

#!/bin/sh
GIT_WORK_TREE=/var/www/www.example.org git checkout -f


In your local git repository:

git remote add web ssh://server.example.org/home/ams/website.git
git push web +master:refs/heads/master


Configuration:

  • /var/www/www.example.org is the public root of this site.
  • /home/ams is the location you created website.git
  • server.example.org is the domain, IP, or host alias of your server

这篇关于我如何:Git单向推/不可编辑工作目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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