使用 Plesk Onyx 的 Git 扩展提交在服务器上所做的更改

Commit changes made on the server with Git extension for Plesk Onyx

是否可以使用 Plesk Git extension 提交直接在服务器上所做的更改(例如,客户上传到其网站的文件)?

该扩展配置为跟踪远程 (GitHub) 存储库,并且提供的唯一选项是“拉取最后一次提交”。它似乎没有提供 CommitPush 功能。

我尝试在通过 ssh 连接到服务器时手动提交本地更改,但是我的工作树中没有 .git 目录,所以我不能 运行一个git命令...

据我所知,Plesk Git 扩展仅创建裸存储库(或仅用人类的意思 "deployment mode"),因此没有工作树并且提交和推送不可用。

此决定是基于 "production server" 上没有 "development"。

我不知道这个扩展将来是否支持非裸存储库。

根据 Plesk 团队成员的说法:

When you use remote repository, the following scenario is assumed - you send the changes to this remote repository, and then Plesk pulls them from the remote repository and deploys them to your web site.

Commit or Push functionality is available in case of scenario when you send the changes from your local repository to Plesk, and then Plesk deploys the changes to your web site.

参见:https://talk.plesk.com/threads/commit-changes-made-on-the-server-with-git-extension-for-plesk-onyx.342362/#post-822292

您可以在 git 服务器上提交和推送。

就我而言,我的网站文件在 /var/www/vhosts/xxx/httpdocs/memberportal 中,git 设置在 /var/www/vhosts/xxx/git/memberportal.git#

如果我转到 /var/www/vhosts/xxx/httpdocs/memberportal 中的 Web 目录,我可以这样调用 git:

git --git-dir ../../git/memberportal.git --work-tree . add .  
git --git-dir ../../git/memberportal.git --work-tree . status  
git --git-dir ../../git/memberportal.git --work-tree . commit -m "My message"
git --git-dir ../../git/memberportal.git --work-tree . push  

但是,每当我从存储库中拉取时,plesk 主机上的所有修改文件都将被删除。这意味着如果您使用 webhook 自动部署,生产服务器上的编辑可能会在您将它们推送到存储库之前被删除。

您可以从服务器压缩和下载网站文件夹并将其解压缩到本地主机并将其推送到git。

我解决这个问题的方法和差不多。唯一的区别是,我不是在工作目录中工作,而是使用 --work-tree 参数从 .git 目录 运行 git

git --work-tree=/var/www/vhosts/xxx/yyy/ <any git command>

最近,我想知道通过 git 补丁而不是从 plesk 推送是否是更好的解决方案。有任何想法或操作方法吗?

编辑: 我已经结束了 git 补丁 方式。为此,我有一个 运行s

的别名
git --work-tree=/var/www/vhosts/project/public_folder --git-dir=/var/www/vhosts/project/git/project.git/ diff > patch-<project>-<now>.patch

然后,我将补丁应用到本地存储库并提交并推送更改。