【问题标题】:Install specific git commit with pip使用 pip 安装特定的 git commit
【发布时间】:2012-11-21 01:50:00
【问题描述】:

我正在开发一个 django 应用程序,我正在使用 pip 来管理我的需求。如何安装特定 git 的提交?

在我的情况下,我需要安装这个提交: https://github.com/aladagemre/django-notification/commit/2927346f4c513a217ac8ad076e494dd1adbf70e1

【问题讨论】:

    标签: git installation commit pip


    【解决方案1】:

    您可以指定提交哈希、分支名称、标签。

    对于分支名称和标签,你也可以安装一个压缩的发行版。这更快、更高效,因为它不需要克隆整个存储库。 GitHub 会自动创建这些捆绑包。

    哈希:

    $ pip install git+git://github.com/aladagemre/django-notification.git@2927346f4c513a217ac8ad076e494dd1adbf70e1
    

    分行名称

    使用 git

    $ pip install git+git://github.com/aladagemre/django-notification.git@cool-feature-branch
    

    或来自源包

    $ pip install https://github.com/aladagemre/django-notification/archive/cool-feature-branch.tar.gz
    

    标签

    用 git

    $ pip install git+git://github.com/aladagemre/django-notification.git@v2.1.0
    

    或来自源包

    $ pip install https://github.com/aladagemre/django-notification/archive/v2.1.0.tar.gz
    

    这是一个没有详细记录的功能,但您可以在https://pip.pypa.io/en/latest/topics/vcs-support/找到更多信息

    【讨论】:

    • 它将添加这条有趣的消息:Could not find a tag or branch '2927346f4c513a217ac8ad076e494dd1adbf70e1', assuming commit.
    • @vlad-ardelean 关于如何告诉 pip 它是一个提交的任何想法?这是在我的部署脚本上输出的,我不想抑制所有标准错误。
    • @ScottStafford 你不应该有一个分支/标签,它被称为提交消息。那会……很奇怪。
    • 另外我会提到git+命令的HTTPS版本:pip install git+https://github.com/gpoore/codebraid@011464539bfb09b8611c8aef0d543532cea958bf。这对于公司 http 代理背后的人来说可能很重要。
    • @LeonardoArroyo 只要您对最新版本的 pip 使用完整的 40 个字符散列,就不再打印警告。见:github.com/pypa/pip/pull/4674
    【解决方案2】:

    只需添加以下行,就可以在项目中使用 requirements.txt 文件自动安装 python 包:

    package-name -e git+https://github.com/owner/repository.git@branch_or_commit#egg={package-name}

    然后运行命令行:

    $ pip install -r requirements.txt

    【讨论】:

    • 对我来说(python3.5 virtualenv 中的 pip 9.0.1)它不起作用:pip install -r requirements.txt 引发“无法检测到需求名称,请使用 #egg= 指定一个”。但它适用于格式 '-e git+github.com/owner/repository.git#egg=branch_or_commit'
    • 您需要在 requirements.txt 文件中使用这种格式。你这样做了吗?
    • 我让它工作了,但这还不清楚。需要在行首有“package_name -e ...”而不仅仅是“-e ...”。
    • 一个工作示例,来自我的 requirements.txt 中的一行:python-openid -e git+https://github.com/openid/python-openid.git@d093a0919198eb53826ae5753e517af10ad95d5b#egg={python-openid}
    • 添加了建议。谢谢。
    【解决方案3】:

    对@hugo-tavares 回答的额外评论:

    如果是私有 GitHub 存储库,则需要使用:

    pip install git+ssh://git@github.com/....
    

    在你的情况下:

    pip install git+ssh://git@github.com/aladagemre/django-notification.git@2927346f4c513a217ac8ad076e494dd1adbf70e1
    

    【讨论】:

      【解决方案4】:

      如果你想创建一个egg包,你仍然可以使用相同的@branch_or_commit appendage:pip install git+ssh://git@github.com/myrepo.git@mybranch#egg=myeggscript

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-02-01
        • 2021-05-27
        • 2018-11-11
        • 2021-01-30
        • 2018-05-02
        • 2022-09-23
        • 2011-05-11
        相关资源
        最近更新 更多