我怎么知道从git安装pip包时使用了哪个提交? [英] How can I know which commit was used when installing a pip package from git?

查看:238
本文介绍了我怎么知道从git安装pip包时使用了哪个提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用 https://pip.pypa从git安装软件包.io / en / stable / reference / pip_install /#git
检出的特定提交是否记录在某处?

解决方案

您可以使用 knittl的想法找到最近的提交 - 下面的唯一修改是解决你将git树与已安装的软件包比较,而不是git存储库的事实:



<由于安装的软件包可能缺少git
存储库的某些目录结构,请为git repo创建一个新目录。我将使用 html5lib 作为示例:

  mkdir〜/ tmp / html5lib 
cd〜/ tmp / html5lib /
git init

现在抓取git tree:

  git remote add foreign https://github.com/html5lib/html5lib-python 
git获取外部

将安装的软件包复制到git repo中:

  rsync -a〜/ .virtualenvs / muffy / lib / python3.4 / site-packages / html5lib〜/ tmp / html5lib / 

运行 git diff 来比较repo的当前状态(与已安装的软件包的代码)到git树中的每个修订版:

 用于$(git rev-list --all)中的REV。 
echo $(git diff --shortstat foreign / master $ REV)$ REV;
完成| sort -n

这取决于改变的文件数量,然后是插入次数,然后是删除次数。
输出结果如下所示:

  1个文件已更改,3个插入(+),1个删除( - )17499b9763a090f7715af49555d21fe4b558958b 
2个文件已更改,10个插入(+),8个删除( - )ec674a97243e76da43f06abfd0a891308f1ff801
3个文件已更改,17个插入(+),12个删除( - )1a28d721091a2c433c6e8471d14cbb75afd70d1c
更改了4个文件, 18个插入(+),13个删除( - )ff6111cd82191a2eb963d6d662c6da8fa2e7ddde
更改了6个文件,19个插入(+),19个删除( - )ea0fafdbff732b1272140b696d6948054ed1d6d2

每行的最后一项是关联的git commit。



如果git历史记录很长,您需要将 git rev-list --all 修改为一系列的提交。例如,使用 git rev-list tag1..tag2 在两个标签之间搜索。如果您大致了解安装软件包的时间,您可能会猜测要使用哪些标签。使用 git tag 显示可能标记的名称。
请参阅文档了解更多选项。


If I install a package from git using https://pip.pypa.io/en/stable/reference/pip_install/#git does the specific commit that was checked out logged somewhere?

解决方案

You could use knittl's idea to find the nearest commit -- the only modification below is to address the fact that you are comparing the git tree to an installed package, not a git repository:

Since the installed package may lack some of the directory structure of the git repository, make a new directory for the git repo. I'll use html5lib for an example:

mkdir ~/tmp/html5lib
cd ~/tmp/html5lib/
git init

Now fetch the git tree:

git remote add foreign https://github.com/html5lib/html5lib-python
git fetch foreign

Copy the installed package into the git repo:

rsync -a ~/.virtualenvs/muffy/lib/python3.4/site-packages/html5lib ~/tmp/html5lib/

Run git diff to compare the current state of the repo (with the installed package's code) to each revision in the git tree:

for REV in $(git rev-list --all); do
    echo $(git diff --shortstat foreign/master $REV) $REV ;
done | sort -n

This sorts by the number of files changed, then the number of insertions, then deletions. The output will look something like this:

1 file changed, 3 insertions(+), 1 deletion(-) 17499b9763a090f7715af49555d21fe4b558958b
2 files changed, 10 insertions(+), 8 deletions(-) ec674a97243e76da43f06abfd0a891308f1ff801
3 files changed, 17 insertions(+), 12 deletions(-) 1a28d721091a2c433c6e8471d14cbb75afd70d1c
4 files changed, 18 insertions(+), 13 deletions(-) ff6111cd82191a2eb963d6d662c6da8fa2e7ddde
6 files changed, 19 insertions(+), 19 deletions(-) ea0fafdbff732b1272140b696d6948054ed1d6d2

The last item on each line is the associated git commit.

If the git history is very long you'll want to modify git rev-list --all to a range of commits. For example, use git rev-list tag1..tag2 to search between two tags. If you know approximately when the package was installed, you might have a good guess for what tags to use. Use git tag to show the names of the possible tags. See the docs for more options.

这篇关于我怎么知道从git安装pip包时使用了哪个提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆