为什么两个单独提交的 'content' 与 GH API 相同?
Why is the 'content' for two separate commits identical from the GH API?
我有两个提交。 This one and this one。我正在使用 Octokit。
我主要对两次提交中与文件 activerecord/lib/active_record/associations.rb
相关的差异感兴趣。
正如您在此处看到的那样,我将这两个提交都放在一个集合中:
[284] pry(main)> commits2.first.sha
=> "c6e01f5b60c4864f0e92149d1e81077519f503d5"
[285] pry(main)> commits2.second.sha
=> "581f12b7b18a6e5205bfabb814f6e9997bf92be8"
请注意,这两个 SHA 都对应于我上面发布的链接中的 SHA,并且都是唯一的(即彼此不同)。
然而,当我获得每个提交的内容时,特别是与我感兴趣的路径相关的内容时,我得到了两个提交的相同结果。
pry(main)> repo
=> "rails/rails"
pry(main)> path
=> "activerecord/lib/active_record/associations.rb"
c1 = client.contents(repo, path: path, sha: commits2.first.sha)
pry(main)> c1.sha
=> "3729e22e6423348aa9282cd17b49c09793ca3a6f"
然后我对第二次提交做同样的事情,我得到以下信息:
pry(main)> c2 = client.contents(repo, path: path, sha: commits2.second.sha)
pry(main)> c2.sha
=> "3729e22e6423348aa9282cd17b49c09793ca3a6f"
请注意 SHA 是相同的。
c1
和 c2
的内容也相同。您可以在下面看到它们:
pry(main)> c1
=> {:name=>"associations.rb",
:path=>"activerecord/lib/active_record/associations.rb",
:sha=>"3729e22e6423348aa9282cd17b49c09793ca3a6f",
:size=>94931,
:url=>
"https://api.github.com/repos/rails/rails/contents/activerecord/lib/active_record/associations.rb?ref=master",
:html_url=>
"https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations.rb",
:git_url=>
"https://api.github.com/repos/rails/rails/git/blobs/3729e22e6423348aa9282cd17b49c09793ca3a6f",
:download_url=>
"https://raw.githubusercontent.com/rails/rails/master/activerecord/lib/active_record/associations.rb",
:type=>"file",
:content=>
"cmVxdWlyZSAnYWN0aXZlX3N1cHBvcnQvY29yZV9leHQvZW51bWVyYWJsZScK\ncmVxdWlyZSAnYWN0aXZlX3N1cHBvcnQvY29yZV9leHQvc3RyaW5nL2NvbnZl\ncnNpb25zJwpyZXF1aXJlICdhY3RpdmVfc3VwcG9ydC9jb3JlX2V4dC9tb2R1\nbGUvcmVtb3ZlX21ldGhvZCcKcmVxdWlyZSAnYWN0aXZlX3JlY29yZC9lcnJv\ncnMnCgptb2R1bGUgQWN0aXZlUmVjb3JkCiAgY2xhc3MgQXNzb2NpYXRpb25O\nb3RGb3VuZEVycm9yIDwgQ29uZmlndXJhdGlvbkVycm9yICM6bm9kb2M6CiAg\nICBkZWYgaW5pdGlhbGl6ZShyZWNvcmQgPSBua
为简洁起见,我截断了 content
。
为什么会这样?如果您手动查看我在顶部发布的两个链接,然后向下滚动到 associations.rb
代码,您将看到两个都对该文件进行了更改。
那么为什么两个提交的 content
是相同的?
很困惑:|
编辑 1
为了回应 Tim 的评论,即提交可能是精心挑选的并且它们确实相同,我又做了两次提交 (this one & this one),但结果似乎是一样的:
[299] pry(main)> commits2.third.html_url
=> "https://github.com/rails/rails/commit/1d2c6ee8f3f7e4b6881f30e6b53582738c2b3ace"
[300] pry(main)> commits2.third.sha
=> "1d2c6ee8f3f7e4b6881f30e6b53582738c2b3ace"
[301] pry(main)> commits2.fourth.html_url
=> "https://github.com/rails/rails/commit/3c01e01ded4e8e87d48e844881c88f6e47cebdf0"
[302] pry(main)> commits2.fourth.sha
=> "3c01e01ded4e8e87d48e844881c88f6e47cebdf0"
pry(main)> c3 = client.contents(repo, path: path, sha: commits2.third.sha)
pry(main)> c3.sha
=> "3729e22e6423348aa9282cd17b49c09793ca3a6f"
pry(main)> c4 = client.contents(repo, path: path, sha: commits2.fourth.sha)
pry(main)> c4.sha
=> "3729e22e6423348aa9282cd17b49c09793ca3a6f"
GitHub API Documentation 建议您必须使用 ref
选项引用所需的 commit/branch/tag,而您使用的是 sha
.
因此正确的代码应该是这样的:
c1 = client.contents(repo, path: path, ref: commits2.first.sha)
c2 = client.contents(repo, path: path, ref: commits2.second.sha)
我有两个提交。 This one and this one。我正在使用 Octokit。
我主要对两次提交中与文件 activerecord/lib/active_record/associations.rb
相关的差异感兴趣。
正如您在此处看到的那样,我将这两个提交都放在一个集合中:
[284] pry(main)> commits2.first.sha
=> "c6e01f5b60c4864f0e92149d1e81077519f503d5"
[285] pry(main)> commits2.second.sha
=> "581f12b7b18a6e5205bfabb814f6e9997bf92be8"
请注意,这两个 SHA 都对应于我上面发布的链接中的 SHA,并且都是唯一的(即彼此不同)。
然而,当我获得每个提交的内容时,特别是与我感兴趣的路径相关的内容时,我得到了两个提交的相同结果。
pry(main)> repo
=> "rails/rails"
pry(main)> path
=> "activerecord/lib/active_record/associations.rb"
c1 = client.contents(repo, path: path, sha: commits2.first.sha)
pry(main)> c1.sha
=> "3729e22e6423348aa9282cd17b49c09793ca3a6f"
然后我对第二次提交做同样的事情,我得到以下信息:
pry(main)> c2 = client.contents(repo, path: path, sha: commits2.second.sha)
pry(main)> c2.sha
=> "3729e22e6423348aa9282cd17b49c09793ca3a6f"
请注意 SHA 是相同的。
c1
和 c2
的内容也相同。您可以在下面看到它们:
pry(main)> c1
=> {:name=>"associations.rb",
:path=>"activerecord/lib/active_record/associations.rb",
:sha=>"3729e22e6423348aa9282cd17b49c09793ca3a6f",
:size=>94931,
:url=>
"https://api.github.com/repos/rails/rails/contents/activerecord/lib/active_record/associations.rb?ref=master",
:html_url=>
"https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations.rb",
:git_url=>
"https://api.github.com/repos/rails/rails/git/blobs/3729e22e6423348aa9282cd17b49c09793ca3a6f",
:download_url=>
"https://raw.githubusercontent.com/rails/rails/master/activerecord/lib/active_record/associations.rb",
:type=>"file",
:content=>
"cmVxdWlyZSAnYWN0aXZlX3N1cHBvcnQvY29yZV9leHQvZW51bWVyYWJsZScK\ncmVxdWlyZSAnYWN0aXZlX3N1cHBvcnQvY29yZV9leHQvc3RyaW5nL2NvbnZl\ncnNpb25zJwpyZXF1aXJlICdhY3RpdmVfc3VwcG9ydC9jb3JlX2V4dC9tb2R1\nbGUvcmVtb3ZlX21ldGhvZCcKcmVxdWlyZSAnYWN0aXZlX3JlY29yZC9lcnJv\ncnMnCgptb2R1bGUgQWN0aXZlUmVjb3JkCiAgY2xhc3MgQXNzb2NpYXRpb25O\nb3RGb3VuZEVycm9yIDwgQ29uZmlndXJhdGlvbkVycm9yICM6bm9kb2M6CiAg\nICBkZWYgaW5pdGlhbGl6ZShyZWNvcmQgPSBua
为简洁起见,我截断了 content
。
为什么会这样?如果您手动查看我在顶部发布的两个链接,然后向下滚动到 associations.rb
代码,您将看到两个都对该文件进行了更改。
那么为什么两个提交的 content
是相同的?
很困惑:|
编辑 1
为了回应 Tim 的评论,即提交可能是精心挑选的并且它们确实相同,我又做了两次提交 (this one & this one),但结果似乎是一样的:
[299] pry(main)> commits2.third.html_url
=> "https://github.com/rails/rails/commit/1d2c6ee8f3f7e4b6881f30e6b53582738c2b3ace"
[300] pry(main)> commits2.third.sha
=> "1d2c6ee8f3f7e4b6881f30e6b53582738c2b3ace"
[301] pry(main)> commits2.fourth.html_url
=> "https://github.com/rails/rails/commit/3c01e01ded4e8e87d48e844881c88f6e47cebdf0"
[302] pry(main)> commits2.fourth.sha
=> "3c01e01ded4e8e87d48e844881c88f6e47cebdf0"
pry(main)> c3 = client.contents(repo, path: path, sha: commits2.third.sha)
pry(main)> c3.sha
=> "3729e22e6423348aa9282cd17b49c09793ca3a6f"
pry(main)> c4 = client.contents(repo, path: path, sha: commits2.fourth.sha)
pry(main)> c4.sha
=> "3729e22e6423348aa9282cd17b49c09793ca3a6f"
GitHub API Documentation 建议您必须使用 ref
选项引用所需的 commit/branch/tag,而您使用的是 sha
.
因此正确的代码应该是这样的:
c1 = client.contents(repo, path: path, ref: commits2.first.sha)
c2 = client.contents(repo, path: path, ref: commits2.second.sha)