如何在Pipfile中引用本地Git仓库的指定分支?
解决Pipfile引用本地仓库分支失败的问题
错误原因
你在配置里同时混用了path和branch参数,这是冲突的:
path用于指向本地已存在的代码目录,此时Pipfile直接读取本地目录的代码,不需要指定分支(因为本地目录已经是对应分支的代码)branch是配合Git仓库地址(git参数)使用的,用来指定拉取远程或本地Git仓库的特定分支,不能和path同时用
两种解决方案
场景1:本地仓库2已切换到feature/my_branch分支
直接移除branch参数,保留本地路径相关配置即可:
repository2 = {editable = true, extras = ["dev"], path = "/Users/name.surname/Projects/repository2"}
执行pipenv lock就能生成锁文件。后续如果仓库2切换分支,重新运行pipenv install更新依赖即可。
场景2:需要直接拉取Git仓库的feature/my_branch分支
把path换成Git仓库地址(远程或本地Git路径),保留branch参数:
- 远程Git仓库示例:
repository2 = {editable = true, extras = ["dev"], git = "https://你的Git仓库地址/repository2.git", branch = "feature/my_branch"}
- 本地Git仓库示例(指向仓库的
.git目录):
repository2 = {editable = true, extras = ["dev"], git = "/Users/name.surname/Projects/repository2/.git", branch = "feature/my_branch"}
执行pipenv lock即可生成锁文件,Pipenv会自动拉取对应分支的代码。
内容的提问来源于stack exchange,提问作者Victor Sotillo
相关产品推荐
相关产品推荐

