OS X: portable Git (aka install multiple Git versions)

Deadly 提交于 2020-01-24 17:56:44

问题


I'm currently trying to install multiple Git versions on OS X for testing purposes. After downloading the OS X installer bundle from git-scm.com (which installs to /usr/local/git), I move it to a different location, e.g. ~/git-1.7.11.1 or ~/git-1.8.1. Unfortunately, Git does not like this move:

$ ~/git-1.7.11.1/bin/git fetch
fatal: Unable to find remote helper for 'https'

or even worse:

$ ~/git-1.7.11.1/bin/git pull
git: 'pull' is not a git command. See 'git --help'.

Did you mean this?
        shell

When I set the path, it also does not work:

$ export PATH=~/git-1.7.11.1/bin:$PATH
$ which git
/Users/xxx/git-1.7.11.1/bin/git
$ git pull
git: 'pull' is not a git command. See 'git --help'.

Did you mean this?
        shell

Is there anything I need to change in the Git bundles, too, to make them portable (aka running at each location)?


回答1:


The git-scm installer does appear to install everything in /usr/local/git (inferred by looking at the uninstall.sh file in the git-scm download). Therefore, renaming the git directory should not be a problem. What you need to do is augment your path as such:

PATH=$PATH:/usr/local/git-1.7.11.1/bin

so that git and all its helper programs can be found.

Note that this approach won't work if you try to call multiple git versions from the same shell; all the versions will get their helper programs from the first directory in PATH.

[edit] You will also need to set the environment variable GIT_EXEC_PATH. Use

git --exec-path

to learn what it currently is and then use a new one with:

git --exec-path=<...git-1.7.11.1/...>

or by defining GIT_EXEC_PATH.

Also it appears that the build path is built into the git executable which may indicate that git expects its supporting files in a default location.

ebg@ebg(147)$ strings git | grep usr
/usr/local/git
/usr/local/bin:/usr/bin:/bin

ebg@ebg(148)$ strings /usr/bin/git | grep usr
/Applications/Xcode.app/Contents/Developer/usr
/usr/local/bin:/usr/bin:/bin

So, use GIT_EXEC_PATH. See the GIT Man Page for more info.




回答2:


I needed to set GIT_EXEC_PATH:

$ ~/git-1.7.11.1/bin/git pull
git: 'pull' is not a git command. See 'git --help'.

Did you mean this?
        shell
$ export GIT_EXEC_PATH=~/git-1.7.11.1/libexec/git-core/
$ ~/git-1.7.11.1/bin/git pull
Password for 'https://xxx': 


来源:https://stackoverflow.com/questions/15787385/os-x-portable-git-aka-install-multiple-git-versions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!