首页 > 解决方案 > 如何在服务器上运行不同版本的 git?

问题描述

我在具有旧版本 git (1.7.1) 的服务器上有一个 git 存储库。我需要一个仅从 git 2.3 开始可用的功能,即我想运行以下命令:

git config receive.denyCurrentBranch updateInstead

在与系统管理员交谈后,他们在服务器上的不同位置安装了最新版本的 git (2.27.0)。使用这个较新的版本,我能够为存储库运行上述命令。

但是,每当我从本地计算机推送到服务器时,都会收到以下错误消息:

fatal: bad config value for 'receive.denycurrentbranch' in ./config
fatal: Could not read from remote repository.

这似乎在暗示,当我push到服务器时,服务器默认运行旧版本的 git。有没有办法告诉服务器从不同的执行路径运行 git?跑步时

git --exec-path=/path/to/new/git/env

我遇到了奇怪的错误,比如 git 忽略 之后的所有内容exec-path,或者完全忽略所有标志。我不确定这个--exec-path标志是否是解决这个问题的正确方法。

标签: gitversion

解决方案


您需要指定新的git-upload-pack/git-receive-pack

cd /path/to/local/repo
git config remote.origin.uploadpack /path/to/new/git/usr/bin/git-upload-pack
git config remote.origin.receivepack /path/to/new/git/usr/bin2/git-receive-pack

这将是确保 git push/pull 与正确的 Git 对话的良好开端。


推荐阅读