github:在下载中查找特定提交的哈希(标签)(如 .zip 或 .tar.gz)?
github: Find hash (tag) of a specific commit in a download (as .zip or .tar.gz)?
场景:我有两个目录来自同一个 github 存储库,但在不同时间下载为 .zip(或者可能是 .tar.gz)。
问题:如何在这两个目录中找到提交哈希?它甚至存储在任何地方吗?
背景:我正在破解一些代码,走神了,我忘记了为什么我有两个不同的目录。目录明显不同(使用 diff -r dir1 dir2),不同之处不仅仅是我的小技巧。这些目录有一个文件 setup.cfg 都包含行版本 = 0.3.5,因此目录是相同的版本/“发布”但不是相同的提交哈希。我想找出提交的哈希值 are/were.
如果它已下载为 zip 或 tar 存档,则它不是提交,哈希 ID 很可能已经消失。我相信 GitHub 将原始哈希 ID 粘贴到扩展的 header 中,因为他们使用 git archive
来做到这一点:
In the [case where a commit hash ID is used to build the archive] ... Additionally the commit ID is stored in a global extended pax header if the tar format is used; it can be extracted using git get-tar-commit-id. In ZIP files it is stored as a file comment.
您将需要原始 tar 或 zip 文件来对此进行测试。如果未压缩:
git get-tar-commit-id < archive
如果已经压缩,请使用 zcat 或 gunzip 或任何适合您系统的方式解压缩:
gunzip < foo.tar.gz | git get-tar-commit-id
例如。
如果您没有原始存档,或者它没有 ID 怎么办?
通常,从提取的源树到特定提交没有唯一映射。从某种意义上说,这无关紧要:如果您可以获得源树的 Git tree 哈希,并且可以找到 all具有该树哈希的提交,那么所有这些提交都是将产生该存档的提交。但是 git archive
可能会省略、添加或替换文件内容。
虽然我有一个程序可以做到这一点,但为某些文件集找到实际的树哈希并不容易here。通读源代码以了解它可以工作的条件。有了它之后,您可以使用 git rev-parse
:
在提交 object 中搜索将其作为 tree
的提交
git rev-list $start_points |
while read $chash; do
thash=$(git rev-parse $chash^{tree})
[ $thash = $searchfor ] && echo "tree found in commit $chash"
done
例如(未经测试,您需要填写一些变量)。
场景:我有两个目录来自同一个 github 存储库,但在不同时间下载为 .zip(或者可能是 .tar.gz)。
问题:如何在这两个目录中找到提交哈希?它甚至存储在任何地方吗?
背景:我正在破解一些代码,走神了,我忘记了为什么我有两个不同的目录。目录明显不同(使用 diff -r dir1 dir2),不同之处不仅仅是我的小技巧。这些目录有一个文件 setup.cfg 都包含行版本 = 0.3.5,因此目录是相同的版本/“发布”但不是相同的提交哈希。我想找出提交的哈希值 are/were.
如果它已下载为 zip 或 tar 存档,则它不是提交,哈希 ID 很可能已经消失。我相信 GitHub 将原始哈希 ID 粘贴到扩展的 header 中,因为他们使用 git archive
来做到这一点:
In the [case where a commit hash ID is used to build the archive] ... Additionally the commit ID is stored in a global extended pax header if the tar format is used; it can be extracted using git get-tar-commit-id. In ZIP files it is stored as a file comment.
您将需要原始 tar 或 zip 文件来对此进行测试。如果未压缩:
git get-tar-commit-id < archive
如果已经压缩,请使用 zcat 或 gunzip 或任何适合您系统的方式解压缩:
gunzip < foo.tar.gz | git get-tar-commit-id
例如。
如果您没有原始存档,或者它没有 ID 怎么办?
通常,从提取的源树到特定提交没有唯一映射。从某种意义上说,这无关紧要:如果您可以获得源树的 Git tree 哈希,并且可以找到 all具有该树哈希的提交,那么所有这些提交都是将产生该存档的提交。但是 git archive
可能会省略、添加或替换文件内容。
虽然我有一个程序可以做到这一点,但为某些文件集找到实际的树哈希并不容易here。通读源代码以了解它可以工作的条件。有了它之后,您可以使用 git rev-parse
:
tree
的提交
git rev-list $start_points |
while read $chash; do
thash=$(git rev-parse $chash^{tree})
[ $thash = $searchfor ] && echo "tree found in commit $chash"
done
例如(未经测试,您需要填写一些变量)。