【问题标题】:How to change version of git used to receive git-push over SSH如何更改用于通过 SSH 接收 git-push 的 git 版本
【发布时间】:2020-01-08 00:49:38
【问题描述】:

我的目标是在笔记本电脑上编写代码,然后推送到 SSH 远程,在那里我可以运行计算量更大的脚本。

[my_laptop]$ git remote -v
my_remote   ssh://username@server.com:/home/username/projects/my_project (fetch)
my_remote   ssh://username@server.com:/home/username/projects/my_project (push)
origin  git@github.com:username/my_project.git (fetch)
origin  git@github.com:username/my_project.git (push)

SSH 远程预装了 git 1.7.1 (CentOS),但我想将 git config 选项 receive.denyCurrentBranch 设置为 updateInstead,这是在 git 2.3.0 中引入的。

我从远程服务器上的源代码安装了 git 2.9.5 并设置了一个别名 git=/home/username/bin/git2,我可以将其验证为使用 git 2.9.5。

[server]$ which git
alias git='git2'
    ~/bin/git2

[server]$ git --version
git version 2.9.5

但是,当我尝试从笔记本电脑推送到遥控器时,我收到“错误的配置值”错误:

[my_laptop]$ git push my_remote my_branch
fatal: bad config value for 'receive.denycurrentbranch' in ./config
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我相信这是因为我的git push 是用 git 1.7.1 而不是 2.9.5 接收的。

[my_laptop]$ ssh -t username@server.com "git --version"
git version 1.7.1
Connection to server.com closed.

[my_laptop]$ ssh -t username@server.com "git2 --version"
git version 2.9.5
Connection to server.com closed.

如何在 SSH 服务器上设置“默认”版本的 git 以使用 2.9.5 而不是 1.7.1?我在服务器上没有管理员权限。

【问题讨论】:

    标签: git ssh


    【解决方案1】:

    仅当您服务器上的 sshd(SSH 守护程序)在 sshd_config 中具有 PermitUserEnvironment 时,修改 .bash_profile 中的 PATH 才有效,如 mentioned here

    如果设置remote.<name>.receivepack看看能不能指定receive-pack的路径

    git -c remote.origin.receivepack=/home/username/git2/bin/git-receive-pack push my_remote my_branch
    

    【讨论】:

      猜你喜欢
      • 2014-04-30
      • 2015-04-16
      • 2016-01-23
      • 1970-01-01
      • 2021-05-31
      • 1970-01-01
      • 1970-01-01
      • 2016-06-30
      • 1970-01-01
      相关资源
      最近更新 更多