使用 pip 安装特定的 git commit

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13685920/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 15:01:15  来源:igfitidea点击:

Install specific git commit with pip

gitinstallcommitpip

提问by kelwinfc

I'm developing a django app and I'm using pip to manage my requirements. How can I do to install a specific git's commit?

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

In my case I need to install this commit: https://github.com/aladagemre/django-notification/commit/2927346f4c513a217ac8ad076e494dd1adbf70e1

就我而言,我需要安装此提交:https: //github.com/aladagemre/django-notification/commit/2927346f4c513a217ac8ad076e494dd1adbf70e1

回答by Hugo Tavares

You can specify commit hash, branch name, tag.

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

For the branch name and the tag, you can also install a compressed distribution. This is faster and more efficient, as it does not require cloning the entire repository. GitHub creates those bundles automatically.

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

hash:

哈希:

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

branch-name

分店名称

With git

用 git

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

or from source bundle

或从源包

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

tag

标签

with git

用 git

$ pip install git+git://github.com/aladagemre/[email protected]

or from source bundle

或从源包

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

It is a not well-documented feature, but you can find more information at https://pip.pypa.io/en/latest/reference/pip_install.html#git

这是一个没有详细记录的功能,但您可以在https://pip.pypa.io/en/latest/reference/pip_install.html#git找到更多信息

回答by PGuiv

An extra comment to @hugo-tavares's answer:

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

If it's a private GitHub repository, you'll need to use:

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

pip install git+ssh://[email protected]/....

In your case:

在你的情况下:

pip install git+ssh://[email protected]/aladagemre/django-notification.git@2927346f4c513a217ac8ad076e494dd1adbf70e1

回答by mannysz

It's possible to automatically install a python package using the requirements.txt file on you project just by adding the following line:

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

-e git+https://github.com/owner/repository.git@branch_or_commit

-e git+https://github.com/owner/repository.git@branch_or_commit

and run the command line:

并运行命令行:

$ pip install -r requirements.txt

$ pip install -r requirements.txt

回答by Dannid

If you want to create an egg package, you can still use the same @branch_or_commit appendage: pip install git+ssh://[email protected]/myrepo.git@mybranch#egg=myeggscript

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