繁体   English   中英

将 git 添加到服务器上的现有项目

[英]Add git to existing project on server

我知道这个问题可能在某处得到了回答,但我没有找到解决方案。 我有一个已经在实时服务器中的项目,我想添加一个 .git 以便能够从我的本地机器拉/推。

我在想我可以在服务器上做: git init git remote add origin git@project.git git add 。 git commit -m "初始提交"

但这似乎不是正确的方法,所以我尝试执行 git init --bare project.git 并从本地克隆,但该目录为空。

有人可以告诉我在这种情况下如何添加 git。 谢谢你。

我想我知道你想做什么,我以前也做过同样的事情。 我想要的是这样的东西,其中两个文件夹都是 Git 存储库

  laptop              server
~/website   <=>   /var/www/html
  .git/             .git/
  index.html        index.html

但是,这是不可能的,因为我无法从我的笔记本电脑推送到/var/www/html因为那不是一个裸存储库。 我也不能使它成为裸仓库,因为裸仓库没有工作树(我需要它,因为那是显示我网站的文件)。

所以我需要一个中间人:

  laptop            server              server
~/website   <=>   website.git   =>   /var/www/html
  .git/                                .git/
  index.html                           index.html

其中website.git是一个裸仓库。 然后我只是在文件website.git/hooks/post-receive中添加一个 post 接收钩子,该cd s 到/var/www/html并从同一硬盘驱动器上的裸仓库中提取。 这是我的钩子

#!/bin/bash

# unset environment set by git
unset $(git rev-parse --local-env-vars)

# go to website and assemble
cd /var/www/html
git fetch origin
git reset --hard origin/master

# Whatever other instruction you need to build the website
# ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM